我和一个朋友共用我的电脑。我已经在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协议中使用公钥认证,您将发现两者都没有
Git配置——本地凭证。助手”“
Git配置——local user.name和Git配置——local user.email
工作,你必须指定私钥属于你想玩的用户,比如
➜ Lang git:(main) ✗ git config --local -l | cat
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
core.ignorecase=true
core.precomposeunicode=true
remote.origin.url=git@github.com:xyz/1A.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.main.remote=origin
branch.main.merge=refs/heads/main
user.name=xyz
user.email=xyz@post.com
credential.helper=
➜ Lang git:(main) ✗ git push
ERROR: Permission to xyz/1A.git denied to abc.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
➜ Lang git:(main) ✗ git config --local core.sshcommand 'ssh -i ~/.ssh/xyz@post.com -F /dev/null'
➜ Lang git:(main) ✗ git push
Enumerating objects: 11, done.
Counting objects: 100% (11/11), done.
Delta compression using up to 8 threads
Compressing objects: 100% (7/7), done.
Writing objects: 100% (7/7), 30.42 KiB | 10.14 MiB/s, done.
Total 7 (delta 1), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (1/1), completed with 1 local object.
To github.com:xyz/1A.git
660593a..2972551 main -> main
➜ Lang git:(main) ✗
如果运行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: