Resetting a GitHub Personal Access Token on MacOS

Personal Access Token’s are used to grant access to one of your repos with specific permissions. They have an expiry, so when one expires you need to recreate a new one, details are here.

If you’re trying to push and your token has expired, you’ll see an error like this:

> git push
remote: Invalid username or password.
fatal: Authentication failed for 'https://github.com/youraccount/yourrepo

The first time accessing a repo requiring authentication is simpler because it will prompt you for your id and password (or token). Once you’ve set one up though, it’s not as obvious how to reset a new token value, since the git cli only gives you the above error, it doesn’t prompt you to enter a new password/token.

To replace your cached credentials, use these steps (from here):

git config --global --unset credential.helper

git credential-osxkeychain erase
host=github.com
protocol=https

Press Return twice on the second step. Close your Terminal, open a new one, then:

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

From your GitHub account, go to Settings from the top right icon, then Developer Settings, then Personal Access Tokens.

Next time you do a push, use the Personal Access Token value when prompted for your password.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.