Configuring credential.helper
On OS X (now macOS), run this in Terminal:
git config --global credential.helper osxkeychain
It enables Git to use file Keychain.app to store username and password and to retrieve the passphrase to your private SSH key from the keychain.
For Windows use:
git config --global credential.helper wincred
For Linux use:
git config --global credential.helper cache // If you want to cache the credentials for some time (default 15 minutes)
OR
git config --global credential.helper store // if you want to store the credentials for ever (considered unsafe)
Note: The first method will cache the credentials in memory, whereas the second will store them in ~/.git-credentials
in plain text format.
Check here for more info about Linux method.
Check here for more info about all three.
Troubleshooting
If the Git credential helper is configured correctly macOS saves the passphrase in the keychain. Sometimes the connection between SSH and the passphrases stored in the keychain can break. Run ssh-add -K
or ssh-add ~/.ssh/id_rsa
to add the key to keychain again.
macOS v10.12 (Sierra) changes to ssh
For macOS v10.12 (Sierra), ssh-add -K
needs to be run after every reboot. To avoid this, create ~/.ssh/config
with this content.
Host *
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/id_rsa
From the ssh_config
man
page on 10.12.2:
UseKeychain
On macOS, specifies whether the system should search for passphrases in the user's keychain when attempting to use a particular key. When the passphrase is provided by the user, this option also specifies whether the passphrase should be stored into the keychain once it has been verified to be correct. The argument must be 'yes' or 'no'. The default is 'no'.
Apple has added Technote 2449 which explains what happened.
Prior to macOS Sierra, ssh
would present a dialog asking for your passphrase and would offer the option to store it into the keychain. This UI was deprecated some time ago and has been removed.
netrc
'. See a full example here. – Antimicrobial.git/config
file of the repository to[email protected]:{username}/{repo}.git
where you replace with your own username and the repo name, obviously. The selected answer is flat-out incorrect. – Bubossh -Tv [email protected]
(replacing example.com with your GitLab domain) Try to push your changes. If it still doesn't work try this:git remote rm origin; git remote add origin git@git.<domain>:<username>/<ProjectName>.git; git push -u origin --all; git push -u origin --tags;
If it still doesn't work, try to re add the private key in the website. Last thing to try, add the key from bash:ssh-add id_rsa
– Pillowgit config --global credential.helper cache
– Superfine