Reputation: 2579
I've my own git account and two git accounts of different client. I'm trying to commit, push or pull from my account but it gives an error of "permission to git is denied."
Could any one guide me how to handle multiple git account.
Thanks
Upvotes: 1
Views: 470
Reputation: 2948
Open config file & add below codes. (change according to your account)
Account 1
# account_1
Host gitlab.com-account_1
HostName gitlab.com
User git
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_account_1
Account 2
# Account2
Host gitlab.com-Account2
HostName gitlab.com
User git
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_Account2
Account 3
# Account_3
Host github.com
HostName github.com
User git
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_Account_3
Add remote url as follows
Account 1
git remote add origin [email protected]_1:group_name/repo_name.git
Account 2
git remote add origin [email protected]:group_name/repo_name.git
Account 3
git remote add origin [email protected]:github_username/repo_name.git
Make sure that IdentityFile names are same as you created during ssh key generation.
Upvotes: 0
Reputation: 18578
I do this with the following trick.
in ~/.ssh/config
have lines similar to this
Host gh-account1
HostName github.com
User git
IdentityFile ~/.ssh/account1_rsa
Host gh-account2
HostName 176.126.246.157
User git
IdentityFile ~/.ssh/account2_rsa
Then instead of the URL github give you use gh-account2:user/repo.git
(This is the clone with ssh url but [email protected]
replaced with gh-account2
)
if you need to push to the same repo with 2 accounts you will need to add multiple remotes
git remote add account1 account1:user/repo.git
then you can go
git push account1 <branch>
you can do this with https linsk (they ask for account name and password each time) but its a lot of typing just to push code
Upvotes: 0
Reputation: 2675
Check this out, this tutorial is for linux users. http://mherman.org/blog/2013/09/16/managing-multiple-github-accounts/#.WE0XEVy77DU
Upvotes: 1