Managing different identities can be difficult with git. One of the ways to make this easy is by configuring the keys specific to the repo in the repo itself:
git config --local user.name "John Doe"
git config --local user.email "john@doe.com"
git config --local core.sshCommand "ssh -i ~/custom/location/id_rsa"
This will be stored in the repo’s git config file .git/config
:
[user]
name = John Doe
email = john@doe.com
[core]
sshCommand = "ssh -i ~/custom/location/id_rsa"
Similarly, to clone a repo with a different identity or the default key, there is a easily forgettable one liner:
git clone -c "core.sshCommand=ssh -i <key_path>" git@github.com:<user>/<repo>.git
This is one of those things, that you don't need daily but super hard to find when you need it. Hence the post!
Since we are here, if you are wondering how to create a new identity for git, its fairly easy:
ssh-keygen -t ed25519 -f ~/.ssh/abc -q -C '' -N ''
Thats all for today! :)
Top comments (0)