Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to update a GitHub access token via command line

I use the git integration with VSCode. I have my new token (obtained through the GitHub web interface). How do I put it in?

The VSCode docs suggest the following:

To execute the 'GitHub: Set Personal Access Token' type Ctrl+Shift+p in VSCode to open the command palette and type 'GitHub: Set Personal Access Token'. You will then be prompted to enter the token generated from GitHub.

This option isn't available in my git integration in VS code. How can I do it from the command line?

like image 454
Matthew Salvatore Viglione Avatar asked Aug 31 '25 15:08

Matthew Salvatore Viglione


2 Answers

If you want to update your GitHub Personal Access Token in VSCode, you can install the GitHub Extension.

You can also update your token via the command line. Note that this method writes your token to the .git/config file in plain text which may expose it for use by others or potential unintentional redistribution.

  1. Open a command line and set the current directory to your project root

  2. Run this command to set remote access via a token:

    git remote set-url origin https://username:[email protected]/username/repository.git

    For example:

    git remote set-url origin https://exampleuser:b8c281*****[email protected]/exampleuser/exampleproject.git

like image 52
Adhi Ardiansyah Avatar answered Sep 02 '25 05:09

Adhi Ardiansyah


This solution avoids the problem of exposing your token in plain text

The problem with the top voted answer is that your token is written to the .git/config file in plain text which exposes it for use by others or potential unintentional redistribution.

First, remove your existing git credentials. The next time you perform a Git operation, you will be prompted for a username and password. Enter the new token as your password.

Clearing credentials on Windows

To clear credentials on Windows, open the Credential Manager (search "credential manager" in the Windows search box). Then select the "Windows Credentials" button, find Git, and click "remove".

enter image description here

enter image description here

like image 24
Matthew Salvatore Viglione Avatar answered Sep 02 '25 06:09

Matthew Salvatore Viglione