Update Remote URL with New Token Github

Update Remote URL with New Token

If you need to update your GitHub token credentials in Visual Studio Code (VSCode) due to expired tokens, security updates or change project folder, follow these steps to ensure a smooth transition. This guide will help you remove the old credentials and configure the new token for seamless Git operations.

Step 1 Generate a New Personal Access Token (PAT)

  • Go to GitHub’s Personal Access Tokens page.
  • Click on “Generate new token”.
  • Provide a name for your token, select the required scopes (typically repo for full control of private repositories), and generate the token.
  • Copy the generated token as you will need it for the next steps.

Step 2 Set the Remote URL with the New Token

Run the following command in the terminal, replacing <username>, <personal-access-token>, and <repository> with your GitHub username, new token, and repository name respectively:

git remote set-url origin https://<username>:<personal-access-token>@github.com/<username>/<repository>.git

Example:

git remote set-url origin https://hambo31:gh**************************************@gi****.com/hambo31/testings.git

Step 3 Push Changes with New Token

After setting the new remote URL, attempt to push your changes. If prompted, use your GitHub username as the username and the new personal access token as the password:

git push origin master

By following these steps, you can easily update your GitHub token credentials in VSCode. This ensures that your Git operations remain seamless and secure with the new token in place. Whether you prefer GUI tools or command line interfaces, this guide covers both approaches to suit your workflow.

Scroll to Top