Skip to content

Git Credentials

Cheng-Yu Hsu edited this page Sep 27, 2016 · 2 revisions

Notes on Git Credentials

Git can store or cache your credentials so you don't need to type them every time.

Types

There're few types of credential store/cache:

  1. Store them into a file
  2. Cache them into a file that will be destroyed after a period
  3. OS native keychain

Configuration

Configure the credential helper using command line.

Synopsis:

$ git config --global credential.helper [type][options]

Usage:

  1. Store the credentials into a file:

    Git will store your credentials in ~/.git-credentials by default.

    $ git config --global credential.helper store
  2. Cache the credentials into a file that will be destroyed after a period:

    Git will store your credential in memory for 900 seconds by default.

    $ git config --global credential.helper cache 

    You can also specify the timeout period using --timeout option.

    $ git config --global credential.helper "cache --timeout=3600" 

    Clear memory cache:

    $ git credential-cache exit
  3. Store credentials in system keychain:

    $ git config --global credential.helper osxkeychain

Remove store/cache policy

$ git config --global --unset credential.helper
$ git config --system --unset credential.helper
$ git config --local --unset credential.helper

Erase and Reset

$ git credential-osxkeychain erase
Erase
$ git credential-osxkeychain erase
> host=github.com
> protocol=https

This will clear password for https://github.com/*.

Clone this wiki locally