这是我遇到的问题。
首先,我正在从事几个不同的项目。 我有两个不同的 github 帐户,在设置其中一个帐户并成功将 repo 推送到它之后,我需要将另一个 repo 提交/推送到第二个帐户,这让我遇到了确切的问题。
如何使用 https 而不是 ssh 在这两个帐户之间切换?
附:我在 Mac 上。
我尝试更改 git config 全局/本地用户名和电子邮件,但没有成功。我不断收到同样的错误:
" remote: Permission to name/repo.git denied to User. fatal: unable to access 'repos address' : The requested URL returned error: 403".
最佳答案
您将需要使用不同的 ssh key 。
阅读完整文档并按照步骤操作。
不同github账户的多个SSH key 设置:
https://gist.github.com/jexchan/2351996
创建不同的公钥
根据文章 Mac Set-Up Git 创建不同的 ssh key
$ ssh-keygen -t rsa -C "your_email@youremail.com"
例如,在以下位置创建了 2 个 key :
~/.ssh/id_rsa_activehacker
~/.ssh/id_rsa_jexchan
将这两个 key 添加到 ssh-agent:
$ ssh-add ~/.ssh/id_rsa_activehacker
$ ssh-add ~/.ssh/id_rsa_jexchan
you can delete all cached keys before
$ ssh-add -D
检查您的 key
$ ssh-add -l
修改ssh配置
$ cd ~/.ssh/
$ touch config
$ subl -a config
将 key 添加到配置文件中:
***
#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
克隆你的 repo 并修改你的 Git 配置
# 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
关于git - 推送存储库时如何在不同用户(github 帐户)之间切换?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35796895/