Git: Credential Helper
The Git credential helper caches your login details so you don't have to enter them every time you perform a remote operation.
Git stores credentials in the configuration hierarchy:
- system → applies to all users on the machine
- global → applies to your user (~/.git-credentials)
- local → applies only to the repository (.git/config) — this takes precedence
~/.git-credentials
This file stores your Git credentials (username and password) when using the 'store' helper.
The file format is simple: each line contains a URL with embedded credentials, like this:
https://username:password@hostname/repo.gitYou can have multiple lines for different hosts or repositories. Git will use the first matching entry it finds when accessing a remote.
Be cautious: this file is stored in plain text, so anyone with access to your user account can read it. Make sure to set appropriate file permissions to restrict access. The file default permissions are usually 600 (read and write for the user only).
Helper Configuration
Store credentials permanently
git config --global credential.helper storeNext time you push, pull, or fetch, git will ask for your username and password, and then store them on disk for a long time and use those credentials for all repositories on given host (github, gitlab, custom git server etc.). Credentials will be stored in ~/.git-credentials.
Cache credentials temporarily
git config --global credential.helper cacheConfigures Git to cache your credentials in memory for a short duration.
Store credentials permanently only for local repo
git config --local credential.helper storeConfigures Git to store your credentials on disk for a long time with precedense over global settings in .git/config.
Store credentials permanently only for local repo in custom location
git config --local credential.helper 'store --file=path/to/credentials/file'Configures Git to store your credentials on disk for a long time with precedense over global settings but in custom location.
Clearing stored credentials
Clear all cached credentials
git credential-cache exitClears all credentials stored in memory by the cache helper.
Manually remove stored credentials from disk
rm ~/.git-credentialsDeletes the file where credentials are stored when using the 'store' helper.
Unset global credential helper configuration
git config --global --unset credential.helperRemoves the credential helper setting from your global Git configuration.
Unset local credential helper configuration
git config --local --unset credential.helperRemoves the credential helper setting from your local Git configuration.