为什么Git不识别来源,我如何纠正这一点,用个人令牌更新remote.orgiing.url



我在GitHub上有一个私人远程存储库,我正试图在我们的AWS服务器上(使用Ubuntu(将其推向生产。我尝试了以下命令,并收到以下错误:

sudo git pull
remote: Support for password authentication was removed on August 13, 2021. Please use a personal access token instead.
remote: Please see https://github.blog/2020-12-15-token-authentication-requirements-for-git-operations/ for more information.
fatal: Authentication failed for 'https://github.com/projectrepo/projectname.git/'

sudo git remote -v 
origin  https://project_username:OLD_PASSWORD@github.com/projectrepo/projectname.git (fetch)
origin  https://project_username:OLD_PASSWORD@github.com/projectrepo/projectname.git (push)

sudo git remote rm origin 
fatal: No such remote: 'origin'

sudo git config --list 
user.name=project_username
remote.origin.url=https://project_username:OLD_PASSWORD@github.com/projectrepo/projectname.git
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true

sudo git remote set-url origin https://project_username:NEW_PERSONAL_TOKEN@github.com/projectrepo/projectname.git
fatal: No such remote 'origin'

为什么Git不能识别origin,我如何更正它来更新remote.origin.url

您使用删除了原点

git remote rm origin

所以难怪它不存在了,你不能用它做任何事情。你可以通过将它添加回来

git remote add origin [address]

最初的错误表明您不应该将HTTPS与基本身份验证一起使用。您应该生成一个个人令牌并将其放入URL,或者使用ssh地址(并使用公钥身份验证(:

remote: Support for password authentication was removed on August 13, 2021. Please use a personal access token instead.
remote: Please see https://github.blog/2020-12-15-token-authentication-requirements-for-git-operations/ for more information.
fatal: Authentication failed for 'https://github.com/projectrepo/projectname.git/'

找到了答案:我意识到问题是remote.origin.url是用OLD_PASSWORD全局设置的,但局部是NEW_PERSONAL_TOKEN.

这是行之有效的:使用sudo git config --global --edit直接编辑全局配置文件。

相关内容