如何设置我的本地 Git 存储库以使用我刚创建的新个人访问令牌?

How do I set up my local Git repo to use the new personal access token I just created?

我有一个现有的 GitHub 存储库在我的 Mac 上本地签出。由于 Git 需要个人访问令牌,我使用此处的说明创建了一个 - https://docs.github.com/en/github/authenticating-to-github/keeping-your-account-and-data-secure/creating-a-personal-access-token 。但是,当我尝试推送我的本地更改时,系统不会提示我输入令牌 ...

$ git push
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: unable to access 'https://github.com/myrepo/maps.git/': The requested URL returned error: 403

如何设置我的本地存储库以使用我刚刚创建的令牌?

生成令牌后,转到 mac 中的 Keychain Access 应用程序。搜索github.com,双击,选择Show Password,然后输入你的macbook password,然后回车。您现在将能够看到密码,只需粘贴您已经生成的令牌,然后保存更改。

就是这样

感谢您的提问,试试这个它会起作用,

git remote set-url origin https://yourgithubusername:yourpersonalaccesstoken@github.com/yourgithubusername/reponame.git

然后,

添加所有更改git add .

提交git commit -m "commit message"

推送更改git push origin main