Git tricks

Caching GitHub password in Git

In Terminal, enter the following:

1
2
git config --global credential.helper cache
# Set git to use the credential memory cache

To change the default password cache timeout, enter the following:

1
2
git config --global credential.helper 'cache --timeout=3600'
# Set the cache to timeout after 1 hour (setting is in seconds)

Or alternatively, store forever:

1
git config --global credential.helper store

Revert local change to previous commit

1
git checkout -- readme.txt # revert readme.txt to previous commit

or

1
2
3
git fetch --all
git reset --hard origin/master
git pull // can be ignored

Revert to status in another branch

1
git checkout <other-branch-name> -- <path to your file_or_folder>