我和一个朋友共用我的电脑。我已经在Windows 7上使用git bash shell推送到GitHub。现在我们在那台电脑上做一个不同的项目,我需要她推到她的账户上。但它一直试图使用我的用户名,并说我没有访问她的存储库:

$ git push her_github_repository our_branch
ERROR: Permission to her_username/repository.git denied to my_username.
fatal: The remote end hung up unexpectedly

重要:2021年8月13日删除了对密码验证的支持。


当前回答

如果你有https://desktop.github.com/ 然后你可以去首选项(或选项)->帐户 然后签出签入。

其他回答

如果您使用不同的windows用户,您的SSH密钥和git设置将是独立的。

如果这对你来说不是一个选择,那么你的朋友应该把你的SSH密钥添加到她的Github帐户。

虽然,之前的解决方案会让你自己推动,但它会让你推动她的回购。如果你不想在同一台电脑的不同文件夹中工作,你可以通过删除config命令的-g标志,在git的本地文件夹中设置用户名和电子邮件:

git config user.name her_username
git config user.email her_email

或者,如果你推送https协议,Github每次都会提示输入用户名/密码(除非你使用密码管理器)。

如果您使用ssh和get

some_username/repository的权限。Git拒绝 Alice_username

虽然你不想推作为Alice_username,确保Alice_username没有你的电脑的ssh密钥添加到它的github帐户。

我从爱丽丝的github账户上删除了ssh密钥,推送成功了。

我也遇到过类似的问题。我有一个工作用的github账户和一个私人账户。在我的mac上,我主要使用我的工作github。我无法说服git通过终端推送到我的私人回购。但当我使用github桌面时,它是有效的。

(我知道肯定有不同的方法,但上面的答案都没用,所以这是阻力最小的方法。)

git config user.name只改变我提交的名称。我还是推不动。这就是我解决它的方法,我认为对我来说是一个简单的方法。

在要使用的计算机上使用的用户名下生成一个SSH密钥 https://help.github.com/articles/connecting-to-github-with-ssh/ 将此键添加到要推送的github用户帐户 https://help.github.com/articles/adding-a-new-ssh-key-to-your-github-account/ 选择SSH克隆

你可以以这个用户推入到那个回购。

如果运行git push后,git要求输入用户密码,但你想以new_user的身份推送,你可能需要使用git配置remote.origin.url:

$ git push
user@my.host.com:either/branch/or/path's password:

此时使用^C退出git推送,并使用following作为new_user进行推送。

$ git config remote.origin.url
user@my.host.com:either/branch/or/path

$ git config remote.origin.url new_user@my.host.com:either/branch/or/path

$ git push
new_user@my.host.com:either/branch/or/path's password: