Git - Credential


Git makes use of a credential helper (an external utility) to be able to retrieve the credentials)

The id of a credential (user, ww) is a URL (Credential context)

It will lookup a credential with the user, protocol, host. By order of precedence, Git will search the following credential URL to find a credential

  • first, git:http://user@hostname:port
  • if not found then, git:http://hostname:port


How to set your credentials

In a remote URL

In a remote url. It works only for ssh or https as the password should be encrypted in transport.

  • on push
git push https://username:[email protected]/username/repository.git
  • on fetch
git fetch https://username:[email protected]/username/repository.git
  • on clone
git clone https://username:[email protected]/username/repository.git
git clone https://username:[email protected]/username/repository.git

Be careful with an old git client before this commit, the credentials appear in all output.

If a user copy-pastes the output to document an error, the token will have a lot of chances to leak. Example:

error: failed to push some refs to 'https://user:[email protected]/org/repo'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')

In the credential manager


  • with the cache credential manager where we set the username for an url
git config --global credential.helper cache
git config credential.https://hostname.username myusername

Helper / Credential Manager


Which credential helper use git now ?

git config --global credential.helper
# or whole path


git help -a | grep credential-
credential-manager      merge-recursive         submodule--helper
  credential-store        merge-resolve           subtree
  credential-wincred      merge-subtree           svn


First, list them, then you can ask the help for one of them with the below command.

Example for credential-store

git help credential-store


Git - Config

git config --global credential.helper foo
#where foo is your credential helper
git config --global credential.helper /path/to/foo


git config --global credential.helper manager
  • for Git Credential Store (File System)
git config --global credential.helper store

Documentation / Reference

Discover More
How to install and store credentials on Linux with Git Credential Manager and pass?

This article shows you how you can store git credential (username and password) on Linux with: the Git Credential Manager and the gpg/pass...

Share this page:
Follow us:
Task Runner