Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to cache https credentials for pushing commits?

I recently switched to synchronizing my repositories to https:// on GitHub (due to firewall issues), and it asks for a password every time.

Is there a way to cache the credentials, instead of authenticating every time that git push?

like image 654
Zepplock Avatar asked Mar 17 '11 17:03

Zepplock


People also ask

What is credentials cache?

A credential cache (or “ccache”) holds Kerberos credentials while they remain valid and, generally, while the user's session lasts, so that authenticating to a service multiple times (e.g., connecting to a web or mail server more than once) doesn't require contacting the KDC every time.

How do I store multiple credentials in Git?

The "easiest" way I found was just to have multiple user accounts on the system, which isn't that convenient. Otherwise if you have one repo and you try and set the user using git config user.name etc, it'll use the wrong password/account anyways for that repo.

Where are Git credentials stored?

The default path for the git credential store is $HOME/. git-credentials (or $XDG_CONFIG_HOME/git/credentials, if the previous location doesn't exist).


1 Answers

Since Git 1.7.9 (released 2012), there is a neat mechanism in Git to avoid having to type your password all the time for HTTP / HTTPS, called credential helpers.

You can just use one of the following credential helpers:

git config --global credential.helper cache 

The credential.helper cache value tells Git to keep your password cached in memory for a particular amount of minutes. The default is 15 minutes, you can set a longer timeout with:

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

Which sets the cache for 1 hour, or:

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

For 1 day. You can also store your credentials permanently if so desired, see the other answers below.

GitHub's help also suggests that if you're on Mac OS X and used Homebrew to install Git, you can use the native Mac OS X keystore with:

git config --global credential.helper osxkeychain 

For Windows, there is a helper called Git Credential Manager for Windows or wincred in msysgit.

git config --global credential.helper wincred # obsolete 

With Git for Windows 2.7.3+ (March 2016):

git config --global credential.helper manager 

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

Nowadays (2020), that would be (on Linux)

Fedora

sudo dnf install git-credential-libsecret git config --global credential.helper /usr/libexec/git-core/git-credential-libsecret 

Ubuntu

sudo apt-get install libsecret-1-0 libsecret-1-dev cd /usr/share/doc/git/contrib/credential/libsecret sudo make git config --global credential.helper /usr/share/doc/git/contrib/credential/libsecret/git-credential-libsecret 
like image 73
Mark Longair Avatar answered Sep 21 '22 05:09

Mark Longair