问题:
执行 git push时报错,fatal: Authentication failed
remote: Anonymous access to XXX/xxx.git denied.
fatal: Authentication failed for 'https://www.github.com/XXX/xxx.git/'
请注意报错信息,本文针对由于远程仓库地址写错(多写了个www)而导致 git push 出错的情况。
解决方法:
执行如下命令修改 remote.origin.url。
git remote remove origin
git remote add origin https://github.com/XXX/xxx.git
git push
解决过程:
试过重置 user.name 和 user.email ,还是报错。下面记录一下我的解决过程:
git config --list 当前的配置是否正确,包括 user.name,user.email,remote 。
user.email=email@yeah.net
user.name=XXX
push.default=matching
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
remote.origin.url=https://www.github.com/XXX/xxx.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.master.remote=origin
branch.master.merge=refs/heads/master
不知道你注意没,上述报错提示中远程库的地址是https://www.github.com....,而不是https://github.com...。所以修改 remote.origin.url。
#git remote 相关命令
git remote set-branches [--add] <name> <branch>...
git remote set-url [--push] <name> <newurl> [<oldurl>]
git remote set-url --add <name> <newurl>
git remote set-url --delete <name> <url>
通过上诉命令先删除再添加,把 remote.origin.url 的值改为 https://github.com/XXX/xxx.git,然后 git push 就可以了。
不知道为什么,我删除不了remote.origin.url ,所以我运行了如下命令。
git remote remove origin
git remote add origin https://github.com/XXX/xxx.git
git push