· Travis Rodgers · Programming · 2 min read
How To Update Your GitHub Personal Access Token (and add origin)
What do you do when your GitHub personal access token expires?
Sure, you create a new one in Github for another 30, 60, or 90 days by going to https://github.com/settings/tokens, clicking Generate New Token, and creating a new token (be sure to at least check the repo scope and also copy your generated token, it’s only shown once).
But how do you update your repo’s remote origin to authenticate with that personal access token?
If you run the command
git remote -v
…it will show you your current origin. And if you authenticate with a personal access token, it may look something like:
https://[email protected]/myusername/travis-media-website.git
The format is https://[PERSONALACCESSTOKEN]@github.com/[USERNAME]/[REPO].git
So to update this expired token, there are two steps:
- Remove your current, expired, remote URL by running:
git remote remove origin
Now by running git remote -v
you’ll see you no longer have a remote origin assigned.
- Now add a new remote with your updated GitHub personal access token:
git remote add origin https://[PERSONALACCESSTOKEN]@github.com/[USERNAME]/[REPO].git
That’s it.
Now you should be able to push, pull, and do whatever your personal access token grants you.