Skip to content

Mohcin Bounouara

Thoughts about software engineering and life

Update GitHub Access Token Locally

When you are working on a local project and using a GitHub Access Token to push your code, you might face an issue when the token expires, and you forget to update it or something like this.

If you try to push or pull your changes, you’ll get an error stating that you are not authorized to perform this action.

To resolve this, you go to your GitHub account and regenerate a new access token, all is good rightnow!

The challenge then becomes: how do you update your project’s Git credentials with the new token?

This process took me over two hours to figure out, but let me show you how to fix it in just a few minutes if you face the same issue.

Assume your project’s URL is:
github.com/UserName/project_name.git

You can use the following command to update your remote URL with the new token:

git remote set-url origin https://UserName:<YOUR_NEW_GITHUB_TOKEN>@github.com/UserName/project_name.git

That’s it! Now you have all set to push and pull your changes.

Quick Explanation:

In this command, we updated the remote URL by embedding the new token directly into the URL. This ensures that Git uses the new token for authentication when interacting with your GitHub repository.