Caching git credentials

During my work as a sysadmin and developer I have to do a lot with git as a vcs. Most of the time I have git repositories which are reachable via ssh. There I don’t have to type (thanks to the ssh key) any password during pull, push and fetch commands. But some repositories are only reachable via https. There I also don’t want to type my password every time.

Git since version 1.7.9

Since git 1.7.9 the option credential exists. So you can use the following credential helper:

git config --global credential.helper cache

The default timeout for the cached credentials are 15 min. If you want to change it, you just can use the following command:

git config --global credential.helper "cache --timeout=3600"

In the commands above you have to replace the cache word with the cache according to your os.

OSX

If you are on OSX, you can use osxkeychain:

git config --global credential.helper osxkeychain

Windows

For windows using msysgit 1.8.1 and above you can use wincred:

git config --global credential.helper wincred

For msysgit versions older than 1.8.1, you first have to download git-credential-winstore and install it in your git bin directory.

Next, make sure that the directory containing git.cmd is in your Path environment variable. The default directory for this is C:\Program Files (x86)\Git\cmd on a 64-bit system or C:\Program Files\Git\cmd on a 32-bit system. An easy way to test this is to launch a command prompt and type git. If you don’t get a list of git commands, then it’s not set up correctly.

Finally use the following command:

git config --global credential.helper winstore

Linux

For Linux, you can use gnome-keyring(or other keyring implementation such as KWallet).

Git before version 1.7.9

If you are using a git version before 1.7.9, you can use a less secure way. Then you can just insert your password in your config file in the repository like the following:

https://you:password@github.com/you/example.git
comments powered by Disqus