推送存储库时,如何在不同用户(github帐户)之间切换?

推送存储库时,如何在不同用户(github帐户)之间切换?,git,github,Git,Github,这就是我遇到的问题 首先,我在做几个不同的项目。 我有两个不同的github帐户,在设置了其中一个帐户并成功地将回购推送到该帐户后,我需要将另一个回购提交/推送到第二个帐户,这就解决了确切的问题 如何使用https而不是ssh在这两个帐户之间切换 我在Mac上 我曾尝试更改git config全局/本地用户名和电子邮件,但没有成功。我不断得到相同的错误,即: “远程:拒绝用户对name/repo.git的权限。 致命:无法访问“repos地址”:请求的URL返回错误:403” 您将需要使用不同的

这就是我遇到的问题

首先,我在做几个不同的项目。 我有两个不同的github帐户,在设置了其中一个帐户并成功地将回购推送到该帐户后,我需要将另一个回购提交/推送到第二个帐户,这就解决了确切的问题

如何使用https而不是ssh在这两个帐户之间切换

我在Mac上

我曾尝试更改git config全局/本地用户名和电子邮件,但没有成功。我不断得到相同的错误,即:

“远程:拒绝用户对name/repo.git的权限。 致命:无法访问“repos地址”:请求的URL返回错误:403”


您将需要使用不同的ssh密钥

阅读此完整文档并按照步骤进行操作

不同github帐户的多个SSH密钥设置:


创建不同的公钥
根据文章macsetupgit创建不同的ssh密钥

$ ssh-keygen -t rsa -C "your_email@youremail.com"
例如,在以下位置创建了两个关键点:

~/.ssh/id_rsa_activehacker
~/.ssh/id_rsa_jexchan
将这两个密钥添加到ssh代理:
检查您的钥匙
修改ssh配置
将密钥添加到配置文件:
***
克隆您的回购并修改您的Git配置
推送您的代码

我们还需要将ssh密钥添加到相应的帐户,否则身份验证将失败

这一款完美无瑕-

$ ssh-add ~/.ssh/id_rsa_activehacker
$ ssh-add ~/.ssh/id_rsa_jexchan
you can delete all cached keys before

$ ssh-add -D
$ ssh-add -l
$ cd ~/.ssh/
$ touch config
$ subl -a config
#activehacker account
Host github.com-activehacker
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_activehacker

#jexchan account
Host github.com-jexchan
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_jexchan
# clone your repo 
git clone git@github.com:activehacker/gfs.git gfs_jexchan

cd gfs_jexchan and modify git config

$ git config user.name "jexchan"
$ git config user.email "jexchan@gmail.com" 

$ git config user.name "activehacker"
$ git config user.email "jexlab@gmail.com" 

# or you can have global 
git config $ git config --global user.name "jexchan" 
git config --global user.email "jexchan@gmail.com"
# add the code and commit it
git add .
git commit -m "your comments"

# push the code to the remote server
git push