Skip to content

Instantly share code, notes, and snippets.

@h4rkl
Created August 16, 2021 22:08
Set multiple git accounts

Setup folder specific .gitconfig

In ~/.gitconfig:

[user]
    name = John Doe
    email = john@doe.tld

[includeIf "gitdir:~/github2/"]
    path = ~/github2/.gitconfig

In ~/github2/.gitconfig:

[user]
    name = Jonny Doe
    email = john@github2.tld

Define a ~/.ssh/config file in which you reference each private keys by their full path:

Host github1
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_repo1

Host github2
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_repo2

Set remote for repo

git remote set-url origin github2:<user>/<repo>.git

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment