git – How to add a GitHub personal access token to Visual Studio Code

git – How to add a GitHub personal access token to Visual Studio Code

Follow these simple steps to set up GitHub authentication with a personal access token:

  1. Open a command line window on your PC or Terminal on Mac
  2. Set the current directory to your project root
    cd C:UsersGiddysourcerepoMySampleProject
    
  3. Run the command to set remote access via a token
    git remote set-url origin https://username:[email protected]/username/repository.git
    

    Example:

    git remote set-url origin https://sampleuser:a7b19929***[email protected]/sampleuser/sampleproject.git
    

Tested on Visual Studio Code (Mac)

no need for an extra extension. I only trust official extensions, sorry.
GitHub extension by KnisterPeter

  1. Generate a personal access token from github.com
  2. Make sure to save your access token (e.g., ghp_pVC*****)
  3. Open your project with Visual Studio Code or navigate to your project in the terminal, cd ~/path/to/your/project
  4. In the Visual Studio Code terminal, git remote set-url origin https://<personal_access_token>@github.com/<your_username or organization_name>/<repo_name>.git
  5. Now you can try git push

Note:

When generating a personal access token, make sure to enable workflow:

Enter

Hint

You can type git remote -v to see your origin or upstream.

origin  https://github.com/<username>/<repo_name>.git (fetch)
origin  https://github.com/<username>/<repo_name>.git (push)
upstream        https://github.com/<username>/<repo_name>.git (fetch)
upstream        https://github.com/<username>/<repo_name>.git (push)

Also after setting git remote set-url origin https://<personal_access_token>@github.com/<your_username>/<repo_name>.git

Your git remote -v should be something like:

origin  https://<your_personal_access_token>@github.com/<username>/<repo_name>.git (fetch)
origin  https://<your_personal_access_token>@github.com/<username>/<repo_name>.git (push)

git – How to add a GitHub personal access token to Visual Studio Code

Related posts

Leave a Reply

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