我和一个朋友共用我的电脑。我已经在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日删除了对密码验证的支持。


当前回答

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

其他回答

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

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

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

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

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

如果这是你的问题

remote: Permission to username1/repo.git denied to username2.
fatal: unable to access 'https://github.com/username1/repo.git/':
The requested URL returned error: 403

除了使用git配置从终端更改用户名和电子邮件:

$ git config --global user.name "Bob"
$ git config --global user.email "bob@example.com"

您需要从钥匙串中删除授权信息。我花了好几个小时才想出这个解决办法。我发现我的钥匙链里也有证书。

打开钥匙链访问,点击所有项目,搜索git。删除所有keychain

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克隆

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

如果您使用ssh和get

some_username/repository的权限。Git拒绝 Alice_username

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

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

这是简单的克隆,请采取的git URL与您的用户名。在提交时,它将询问您的新用户密码。

Eg:

Git克隆https://username@github.com/username/reponame.git

Git克隆https://username@bitbucket.org/username/reponame.git