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


当前回答

如果您使用ssh和get

some_username/repository的权限。Git拒绝 Alice_username

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

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

其他回答

我使用自定义的IdentityFile设置了一个ssh别名,并重写了起源,以使用我的自定义me-github主机名。

#when prompted enter `id_rsa_user1` as filename
ssh-keygen -t rsa

# ~/.ssh/config
Host user1-github
HostName github.com
Port 22
User git
IdentityFile ~/.ssh/id_rsa_user1

#check original remote origin url
git remote -v
origin git@github.com:user1/my-repo.git

#change it to use your custom `user1-github` hostname
git remote rm origin
git remote add origin git@user1-github:user1/my-repo.git

如果运行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凭证 删除通用凭证下的条目 再次尝试连接。

我最喜欢这样做。

git push https://username@github.com/username/repo

这将提示输入密码,因此您不必在shell中以纯文本的形式编写密码。

本例将值johndoe@example.com写入配置名user.email。它使用——global标志,所以这个值是为当前操作系统用户设置的。

$ git config --global user.name "John Doe"
$ git config --global user.email johndoe@example.com