Store git credentials in cache in Linux console

A while ago I had to use my private GitHub user on a shared system. Therefore, I wasn’t willing to save my credentials on the server. This brought me in a somewhat annoying situation.
Whenever I wanted to push to the git repo of the current project, I had to fill in my username as well as the corresponding 40 character token generated by GitHub. The utilization of such a token is unavoidable when using two-factor authentication.

Potential Solution

A simplistic solution for this is caching your git credentials. You won’t have to enter them in all the time, while not indefinitely storing them on the server. This is way more convenient the not storing your login data at all, while limiting the risk of someone else getting access to your account.


Your credential can easily be cached using the git credential storage. It can be setup by running the following command:

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

This will enable caching of git credential with a cache timeout of 3600 seconds (one hour).

You can alternatively use a cache without a timeout with the following command:

git config --global credential.helper cache