我和一个朋友共用我的电脑。我已经在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每次都会提示输入用户名/密码(除非你使用密码管理器)。

您可以使用不同的帐号进行推送。 例如,如果您的帐户是存储在.gitconfig中的帐户A,您想使用帐户B,它是您想要推送的回购的所有者。

账号B: B_user_name, B_password SSH链接示例:https://github.com/B_user_name/project.git

B账号推送为:

$ git push https://'B_user_name':'B_password'@github.com/B_user_name/project.git

查看.gitconfig中的帐户

$git配置——global——list $git配置——global -e(也可以更改帐户)

这应该是有效的: Git推送源local-name:remote-name

更好的是,对于GitLab,我使用了第二个“origin”,即“origin2”:

Git远程添加origin2… 然后

Git推送origin2 master

传统的(短的)git推送应该隐式地工作,就像第一个“origin”一样。

这对我有用,它会提示输入用户名和密码

git config --local credential.helper ""
git push origin master

如果运行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: