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

123*_*qwe 7 git github

这是我遇到的问题.

首先,我正在开展几个不同的项目.我有两个不同的github帐户,在设置其中一个并成功推送回购后,我需要提交/推送其他回购到第二个帐户,这让我遇到了确切的问题.

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

PS:我在Mac上.

我试图改变git config全局/本地用户名和电子邮件,但它没有成功.我一直得到同样的错误:

"remote:对用户拒绝命名/ repo.git的权限.致命:无法访问'repos地址':请求的URL返回错误:403".

Cod*_*ard 8

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

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

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

https://gist.github.com/jexchan/2351996


create different public key

根据文章Mac Set-Up Git创建不同的ssh密钥

$ ssh-keygen -t rsa -C "your_email@youremail.com"
Run Code Online (Sandbox Code Playgroud)

例如,在以下位置创建了2个密钥:

~/.ssh/id_rsa_activehacker
~/.ssh/id_rsa_jexchan
Run Code Online (Sandbox Code Playgroud)

Add these two keys to the ssh-agent:

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

$ ssh-add -D
Run Code Online (Sandbox Code Playgroud)

check your keys

$ ssh-add -l
Run Code Online (Sandbox Code Playgroud)

Modify the ssh config

$ cd ~/.ssh/
$ touch config
$ subl -a config
Run Code Online (Sandbox Code Playgroud)

Add the keys to the config file:***

#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
Run Code Online (Sandbox Code Playgroud)

Clone you repo and modify your Git config

# 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"
Run Code Online (Sandbox Code Playgroud)

push your code

# add the code and commit it
git add .
git commit -m "your comments"

# push the code to the remote server
git push
Run Code Online (Sandbox Code Playgroud)