我和一个朋友共用我的电脑。我已经在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日删除了对密码验证的支持。
如果这是你的问题
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
您可以使用不同的帐号进行推送。
例如,如果您的帐户是存储在.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(也可以更改帐户)