问题
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
回答1:
Check this out, this tutorial is for linux users. http://mherman.org/blog/2013/09/16/managing-multiple-github-accounts/#.WE0XEVy77DU
回答2:
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 git@github.com 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
回答3:
- Go to ~/.ssh
- Create a file named config(have no extension )
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_1Account 2
# Account2 Host gitlab.com-Account2 HostName gitlab.com User git PreferredAuthentications publickey IdentityFile ~/.ssh/id_rsa_Account2Account 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 git@gitlab.com-account_1:group_name/repo_name.gitAccount 2
git remote add origin git@gitlab.com-Account2:group_name/repo_name.gitAccount 3
git remote add origin git@github.com:github_username/repo_name.git
Make sure that IdentityFile names are same as you created during ssh key generation.
来源:https://stackoverflow.com/questions/41082552/handle-multiple-git-account