Skip to content

Instantly share code, notes, and snippets.

@pradeepsng30
Last active October 4, 2020 22:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pradeepsng30/1cf0c4ff1eeedfdc60328f831be9adb5 to your computer and use it in GitHub Desktop.
Save pradeepsng30/1cf0c4ff1eeedfdc60328f831be9adb5 to your computer and use it in GitHub Desktop.
Multiple git accounts accounts
#In your ~/.gitconfig you can put something like this.
# git version > 2.13
# https://stackoverflow.com/questions/8801729/is-it-possible-to-have-different-git-config-for-different-projects/43884702#43884702
[includeIf "gitdir:~/company_a/"]
path = .gitconfig-company_a
[includeIf "gitdir:~/company_b/"]
path = .gitconfig-company_b
#Example contents of .gitconfig-company_a
[user]
name = Pradeep singh
email = pradeep@companya.net
#Example contents of .gitconfig-company_b
[user]
name = Pradeep Singh
email = ps@companyb.com
# create two rsa keys with different name. add corresponding key in git accounts (.pub files)
# in ~/.ssh/config
# ref - https://medium.freecodecamp.org/manage-multiple-github-accounts-the-ssh-way-2dadc30ccaca
# Personal account, - the default config
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa
# Work account-1
Host github.com-work_user1
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_work_user1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment