─[$] cat ~/.gitconfig
[user]
name = Shirish Agarwal
email = xxxx@xxxx.xxx
[core]
editor = leafpad
excludesfiles = /home/shirish/.gitignore
gitproxy = \"ssh\" for gitorious.org
[merge]
tool = meld
[push]
default = simple
[color]
ui = true
status = auto
branch = auto
Now I want to put my git credentials for github, gitlab and gitorious so each time I do not have to lookup the credentials on the browser. How can this be done so it's automated ?
I am running zsh
Best Answer
Using SSH
The common approach for handling git authentication is to delegate it to SSH. Typically you set your SSH public key in the remote repository (e.g. on GitHub), and then you use that whenever you need to authenticate. You can use a key agent of course, either handled by your desktop environment or manually with
ssh-agent
andssh-add
.To avoid having to specify the username, you can configure that in SSH too, in
~/.ssh/config
; for example I haveand then I can clone using
(note the absence of a username there).
Using
gitcredentials
If the SSH approach doesn't apply (e.g. you're using a repository accessed over HTTPS), git does have its own way of handling credentials, using
gitcredentials
(and typicallygit-credential-store
). You specify your username usingand the credential helper using
(specify
--global
if you want to use this setup everywhere).Then the first time you access a repository, git will ask for your password, and it will be stored (by default in
~/.git-credentials
). Subsequent accesses to the repository will use the stored password instead of asking you.