Table of Contents

Git - Credential

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

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.

git push https://username:[email protected]/username/repository.git
git fetch https://username:[email protected]/username/repository.git
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:

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

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

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
git config --global credential.helper store

Documentation / Reference