TIL - git credential storage

TIL, Today I Learned, is more of a "I just figured this out: here are my notes, you may find them useful too" rather than a full blog post

When using SSH as transport protocol for connecting to remotes you could use a key without need to type a username nor password. Unfortunately, this is not possible when the underlaying protocol is HTTPS as it requires a username and password for every connection made.

This is where git credential store gets a chance to shine.

Credential storage

Git has a credential system. All you need to do is to set the credential.helper in your .gitconfig.

Possible values are:

  • none, this is the default behavior. You will be promted for username and password for every connection made.
  • cache, this option caches the credentials in memory for a certain period of time. Default is 15 minutes. The passwords are purged after this period.
  • store, saves the credentials in a (plain-text) file.

For example:

$ git config credential.helper store

Will create this entry in your .gitconfig:

[credential]
        helper = store

The default storage file is ~/.git-credentials, you may change it by including the --file option. E.g.:

$ git config credential.helper 'store --file ~/.my-secrets'

For more information, see the manpage for gitcredentials [1].

KAS

KAS [2] is my favorite tool to setup bitbake based projects. I do always build my images using kas-container, as the state of my Archlinux setup is not always... compatible. (I love rolling distributions though).

However, many tools, including kas-container, makes use of git credential files for authentication.

kas-container has the --git-credential-store <file> option to specify the credential file.