Search code examples
gitgithubtoken

Github personal access token


I just found out that from the 13th that support for password authentication was removed, and instead, I should use a personal access token. I generated the token and followed the steps in the link provided in the terminal but it still gives me some issues when I am trying to push. Does anyone know why?

[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

Solution

  • That could mean your old credential (password) is still stored in the Git credential helper.

    Check the output of git config --global credential.helper: it could have cached another user/email/password.
    If that setting is xxx, type:

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

    By 'xxx', I mean "the output of the git config --global credential.helper".
    Do not use 'xxx': replace it.

    You will check if there is any credential already stored.
    If it is:

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

    The next push will prompt for your new credentials (token).

    For instance, if the output is: osxkeychain, type (Mac only):

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

    Both commands remove the github.com entry from your KeyChain.