Table of Contents

About

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

Management

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

Example:

  • 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

Get

Which credential helper use git now ?

git config --global credential.helper
manager
# or whole path
/usr/local/bin/git-credential-manager

List

  • Credential are listed by URL. Example:
echo url=https://github.com/gerardnico/eraldy.com.git | git credential fill
protocol=https
host=github.com
path=gerardnico/eraldy.com.git
username=
password=gerardnico

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

Help

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

Set

Git - Config

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

Example:

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

Documentation / Reference