How to cache https credentials for pushing commits to git repository ?
This sneppet will guide you on how to cache https credentials for pushing commits to git repository using git config command.
git config command
The git config command is used to set or retrieve configuration options for Git. It can be used various purposes such as configuring user information, repository settings, and behavior of Git.
Below are the common uses of git config:
To set your name and email address: git config –global user.name “Your Name” and git config –global user.email “[email protected]”
You can set the default editor: git config –global core.editor “your_editor”
Set the default merge tool: git config –global merge.tool “your_merge_tool”
Configure Git to use a specific credential helper: git config –global credential.helper “your_helper”
Note, the –global flag will se the configuration globally which will affect all the repositories in your system. And if you don’t use –global flag, then the configuration option will be set only for the current repository.
Cache https credentials for pushing commits
You can use git config command to store your credentials in the Git configuration file.
For example,
git config --global credential.helper cache
Note, the above command will cache the credentials in memory only for a short period of time. By default the credentials will be cached/ stored only for 900 seconds or 15 minutes.
In order to store the credentials for a longer time, you must specify the timeout value.
For example,
To set the Git credential helper to use the cache credential helper with a timeout of 1 hour, run the following command
git config --global credential.helper 'cache --timeout=3600
The above cache credential helper will store the credentials for a duration specified (i.e., 1 hour) in the memory. If you are pushing commits to a Git repository more frequently, then this feature would be more helpful for you as you no need to enter credentials every time.
Cache credentials using store credential helper
This is another alternative way to store your credentials.
For example,
git config --global credential.helper store
Above command is using store credential helper to store your credentials in a file on your disk. Please note, this command will store the credentials in a file ~/.git-credentials.
You’ll Also Like
- Throw away the local commits from your branch in Git ?
- Update or sync a forked repository on GitHub?
- Your branch and ‘origin/main’ have diverged, how to fix this ?
- How to connect to Github using SSH ?
- How do you do undo git reset –hard HEAD^ and revert to previous commit ?
- Git – How to compare files in two different branches
- Git not working with a proxy server – gnutls_handshake() failed
- npm ERR! enoent spawn git ENOENT
- GitHub unable to access HTTPS and SSL routines error
- Remove http and https proxy settings of npm and git ?
- Fix Nodejs Error: ENOENT: no such file or directory
- What is the purpose of Git Stash command ?