Remember Git user and password when commiting

Asked

Viewed 945 times

2

Every time I commit, Git asks me for my username and password. Is there any way to cache credentials and avoid having to type all the time?

Use git repositories with HTTPS and non-SHS connection.

2 answers

3


To store your credentials, please install osxkeychain helper making:

git credential-osxkeychain

Then set up the credential.helper to store your credentials.

On the Mac:

git config --global credential.helper osxkeychain

On Windows:

git config --global credential.helper wincred

1

As described in the session 7.4 Git Tools - Credential Storage of Git Book:

If you use transportation SSH to connect to Git remote, is possible to have a key without a passphrase, which allows to transfer data safely without entering your username and password. No however, this is not possible with the protocols HTTP - every connection needs a username and password. This gets even harder for systems with two-factor authentication, where the token used by a password is randomly generated and unpronounceable.

Fortunately, Git has a credential system that can help therein.

Here are some options provided by the tool:

  • Default is not to cache. Each connection will require your username and password.

  • The waycachekeeps the credentials in memory for a certain period of time. None of the passwords are stored on disk and they are removed from cache after 15 minutes by default.

  • The waystoresaves credentials in a text file no formatting on the disk and they never expire. That means which, until you change your password to the Git, you never you will need to enter your credentials again. The downside of this approach is that its passwords are stored in unencrypted text in a simple file in your home directory.

  • If you’re wearing one Mac, the Git comes with a wayosxkeychain, that stores credentials in secure keys attached to your system account. This method stores credentials on the disk and they never expire, but they are encrypted with the same system that stores certificates HTTPS and automatic filling of Safari.

  • If you use the Windows, can install the Git Credential Manager for Windows. This is similar toosxkeychaindescribed above, but uses the Windows Credential Store for control confidential information.

You can choose one of these methods by setting a value of git configuration:

$ git config --global credential.helper cache

Some of these auxiliary commands have options. "store" accepts a argument --file <caminho>, that customizes where the text file simple is saved (the default is~/.git-credentials). The "cache" helper accepts the option --timeout <segundos>, amending the quantity of time your daemon (which retains the password) is kept running (the standard is "900" or 15 minutes).

See an example of how you set up the "store" helper with a custom file name:

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.