首页 > 解决方案 > Github 个人访问令牌

问题描述

我刚刚发现,从 13 日起,对密码身份验证的支持已被删除,而我应该使用个人访问令牌。我生成了令牌并按照终端中提供的链接中的步骤操作,但是当我尝试推送时它仍然给我一些问题。有谁知道为什么?

[kinzluiz:...ch-7-object-oriented-design]$ git status                  (main✱) 
On branch main
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
    new file:   louis/.classpath
    new file:   louis/.gitignore
    new file:   louis/.project
    new file:   louis/src/deckofcards/BlackJack.java
    new file:   louis/src/deckofcards/Card.java
    new file:   louis/src/deckofcards/Deck.java
    new file:   louis/src/deckofcards/Suit.java
    new file:   louis/src/module-info.java

Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
    modified:   ../ch2-linked-lists/Louis/linkedlistctci.py
    deleted:    ../ch2-linked-lists/Louis/main.py
    modified:   ../ch3-stacks-and-queues/louis/main.py

Untracked files:
  (use "git add <file>..." to include in what will be committed)
    ../ch1-arraysAndStrings/Louis/.gitignore
    ../ch3-stacks-and-queues/.idea/

[kinzluiz:...ch-7-object-oriented-design]$ git commit -m "deck of cards "                                                                                                                        (main✱) 
[main e6676a6] deck of cards
 8 files changed, 103 insertions(+)
 create mode 100644 ch-7-object-oriented-design/louis/.classpath
 create mode 100644 ch-7-object-oriented-design/louis/.gitignore
 create mode 100644 ch-7-object-oriented-design/louis/.project
 create mode 100644 ch-7-object-oriented-design/louis/src/deckofcards/BlackJack.java
 create mode 100644 ch-7-object-oriented-design/louis/src/deckofcards/Card.java
 create mode 100644 ch-7-object-oriented-design/louis/src/deckofcards/Deck.java
 create mode 100644 ch-7-object-oriented-design/louis/src/deckofcards/Suit.java
 create mode 100644 ch-7-object-oriented-design/louis/src/module-info.java
[kinzluiz:...ch-7-object-oriented-design]$ git push                                                                                                                                              (main✱) 
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/AisosaUtieyin/ctci.git/': The requested URL returned error: 403

标签: gitgithubtoken

解决方案


这可能意味着您的旧凭证(密码)仍存储在 Git 凭证助手中。

检查输出git config --global credential.helper:它可能缓存了另一个用户/电子邮件/密码。
如果该设置为xxx,请键入:

printf "protocol=https\nhost=github.com"| git-credential-xxx get

' xxx',我的意思是“的输出git config --global credential.helper”。
不要使用' xxx':替换它。

您将检查是否已存储任何凭据。
如果是:

printf "protocol=https\nhost=github.com"| git-credential-xxx erase

下一次推送将提示您输入新凭据(令牌)。

例如,如果输出为:osxkeychain,请键入(仅限 Mac):

printf "protocol=https\nhost=github.com"| git-credential-osxkeychain erase
# Or:
security delete-internet-password -l github.com

这两个命令都从您的KeyChain中删除该github.com条目。


推荐阅读