Copy (scp) file from remote server to Mac using ssh tunnel
June 17, 2018
Access AWS S3 bucket from another account using bucket policy
August 2, 2018

Adding multiple git accounts on same computer

So if you have multiple git accounts, for example, one from the company and one is your personal, then how will you manage them on the same computer to avoid the conflicts.

Here is an easy way I use.

  • Go to ~/.ssh
  • Create a file named config(have no extension )
  • Open config file & add below codes. (change according to your account)

 

  1. Account 1
# account_1
Host gitlab.com-account_1
HostName gitlab.com
User git
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_account_1

2. Account 2

# Account2
Host gitlab.com-Account2
HostName gitlab.com
User git
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_Account2

3. Account 3

# Account_3
Host github.com-Account3
HostName github.com
User git
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_Account_3
  • Add remote URL as follows
    1. Account 1
      git remote add origin git@gitlab.com-account_1:group_name/repo_name.git
      
    2. Account 2
      git remote add origin git@gitlab.com-Account2:group_name/repo_name.git
      
    3. Account 3
      git remote add origin github.com-Account3:github_username/repo_name.git
      

Note: Make sure that IdentityFile names are same as you created during ssh key generation.

Bitnami