Configuring git client for multiple git servers

946 views Asked by At

I need to connect to multiple Git servers with different credentials for my work. I have my personal repository [email protected], my office work repository [email protected] and my customer work repository [email protected]

I need to regularly access and push code to these different repositories with different credentials (which have access to the respective repositories)

How do I configure my git client (I am using git shell - powershell on Windows) to prompt me for user id and password everytime I connect to a remote repository? Ideally, I would prefer not to have to manage certificates.

Note: I have already set my global variables. Not able to unset it now.

If git bash is preferable over git shell, I am open to that as well. I just find git shell easier to deal with since I am used to Windows environment.

1

There are 1 answers

0
hurturk On

You can benefit from .ssh/config to differ between your git accounts over ssh. Pay attention how domains are different and keys are pointed:

#account1
Host github.com-account-one
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_rsa_account_one

#account2
Host github.com-account-two
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_rsa_account_two

For e.g. to use account1, make sure you set origin url or clone from github.com-account-one in your local repository, proper login information will follow:

 git clone ssh://[email protected]:/MyRepo/myrepo.git