DEV Community

Jikku Jose
Jikku Jose

Posted on • Originally published at jikkujose.in

Git Repo Specific Keys

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"
Enter fullscreen mode Exit fullscreen mode

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"

Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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 ''
Enter fullscreen mode Exit fullscreen mode

Thats all for today! :)

Top comments (0)