Is there a way to cache git credentials that doesn’t expire upon a machine restart?

Viewed 131

There are a million posts here about how to cache credentials with git. But none of them seem to hold if the machine does a reboot. Is there a way to cache credentials that lasts upon machine restarts?

1 Answers

Yes, on Debian and Ubuntu, you can use the libsecret credential helper. That will save the username and password or token in your desktop environment's key chain for future use.

Unfortunately, it is not built by default. You can build it yourself by performing the following steps (assuming that ~/bin in in your PATH):

$ cp -a /usr/share/doc/git/contrib/credential/libsecret /tmp
$ cd /tmp/libsecret
$ sudo apt install libsecret-1-dev libglib2.0-dev build-essential
$ make
$ cp git-credential-libsecret ~/bin

You can then do run git config --global credential.helper libsecret. When you're prompted for your credentials, enter them as normal and then they will be saved indefinitely. Note that they will be unlocked by default when you log in.

Related