16

After creating a token, how do you unset the existing password and use the token instead?

I tried running osxkeychain command git config --global credential.helper osxkeychain but it doesn't change anything. I also tried unsetting the user password with git config --global --unset user.password, and I tried opening Keychain Access application and delete GitHub entries, but neither worked.

stevec
  • 27,285
  • 13
  • 133
  • 181

3 Answers3

34

Step 1

Copy this into your terminal to unset existing GitHub login credentials:

git config --global --unset credential.helper
git credential-osxkeychain erase
host=github.com
protocol=https

Step 2

Open a new terminal window, and set the name and email for commits:

git config --global user.name "Your Name"
git config --global user.email you@example.com

Step 3

Run a git push or git clone a private repository so GitHub prompts you to enter your username and password.

For the username, simply enter your email.

For the password paste in your token (i.e. copy the token from GitHub website where you created it and paste it in).

stevec
  • 27,285
  • 13
  • 133
  • 181
  • 1
    I am running old High Sierra and it hangs at `git credential-osxkeychain erase`. – bomben Feb 06 '22 at 11:38
  • 2
    @bomben I just read [this](https://superuser.com/a/1565435/928461) and I think you need to copy all 4 lines in the first code section of my answer, then hit enter twice and it should work :) – stevec Feb 06 '22 at 11:41
  • Thanks for the fast reply. However, I used PyCharm now to set things up. https://stackoverflow.com/questions/22348093/pycharm-github-push-failed-fatal-authentication-failed/71007043#71007043 – bomben Feb 06 '22 at 12:35
11

The below command worked for me on mac as mentioned in https://gist.github.com/jonjack/bf295d4170edeb00e96fb158f9b1ba3c.

security delete-internet-password -l github.com

After running this command in terminal, run a git clone command and it will ask you the username and password. On password please provide your access token which you created from the github web portal.

Alwin Jose
  • 500
  • 4
  • 10
6

TLDR; your token will be your new password. Storing it in the mac keychain makes it a hassle that you don't have to track. Here's the steps on how to update your password with the token.

I see that you've already created a token, which if reading the deprecation notice you might think that's all you need to do. Here's the instructions on creating a token for anyone that hasn't yet: https://docs.github.com/en/github/authenticating-to-github/keeping-your-account-and-data-secure/creating-a-personal-access-token#using-a-token-on-the-command-line

But as you've mentioned, the next step is to replace using a password with instead using the token.

@stevec shared correctly how to do this on the terminal, but you may also open the keychain app and do it there.

  1. Use the mac search for "keychain" and open Keychain Access.app
  2. Search for GitHub. You may see two options: an application password and an internet password
  3. Open the application password. You may check the box for "Show password and likely see that this still uses your password rather than the token.

Replace that password with your token. That worked for me.

windyvation
  • 415
  • 3
  • 10