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:\Users\Giddy\source\repo\MySampleProject
    
  3. Run the command to set remote access via a token

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

    Example:

    git remote set-url origin https://sampleuser:a7b19929***58fe65d1c@github.com/sampleuser/sampleproject.git
    

Update (March 2025)

GitHub now requires fine-grained personal access tokens (PATs) for most new workflows. Classic tokens still work if you already created them, but new tokens should be generated as fine-grained for better security.

Steps:

  1. Generate a fine-grained token from your GitHub account:

    • Go to Settings → Developer settings → Personal access tokens → Fine-grained tokens.
    • Choose the repository or scope permissions you need.
    • Copy the token (you won’t be able to see it again).
  2. In Visual Studio Code, the recommended way is to use the built-in GitHub authentication instead of embedding tokens in remotes:

    • Press F1 → "GitHub: Sign in" → follow the browser login flow → paste your token if prompted.
    • VS Code stores the token securely in the system keychain/credential manager.
    • Done.
  3. If you still want to update your remote manually with the token (not recommended for long-term use):

    Use with AIgit remote set-url origin https://<USERNAME>@github.com/<USERNAME>/<REPOSITORY>.git
    

    Then push/pull, and when Git asks for a password, use your personal access token instead of your GitHub password.

    Note: Avoid putting the token directly in the remote URL (as in the older example). This is insecure and may expose your token in logs or config files.

Answer from Giddy Naya on Stack Overflow
Top answer
1 of 13
165

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:\Users\Giddy\source\repo\MySampleProject
    
  3. Run the command to set remote access via a token

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

    Example:

    git remote set-url origin https://sampleuser:a7b19929***58fe65d1c@github.com/sampleuser/sampleproject.git
    

Update (March 2025)

GitHub now requires fine-grained personal access tokens (PATs) for most new workflows. Classic tokens still work if you already created them, but new tokens should be generated as fine-grained for better security.

Steps:

  1. Generate a fine-grained token from your GitHub account:

    • Go to Settings → Developer settings → Personal access tokens → Fine-grained tokens.
    • Choose the repository or scope permissions you need.
    • Copy the token (you won’t be able to see it again).
  2. In Visual Studio Code, the recommended way is to use the built-in GitHub authentication instead of embedding tokens in remotes:

    • Press F1 → "GitHub: Sign in" → follow the browser login flow → paste your token if prompted.
    • VS Code stores the token securely in the system keychain/credential manager.
    • Done.
  3. If you still want to update your remote manually with the token (not recommended for long-term use):

    Use with AIgit remote set-url origin https://<USERNAME>@github.com/<USERNAME>/<REPOSITORY>.git
    

    Then push/pull, and when Git asks for a password, use your personal access token instead of your GitHub password.

    Note: Avoid putting the token directly in the remote URL (as in the older example). This is insecure and may expose your token in logs or config files.

2 of 13
70

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:

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)
Discussions

VSCode + Gitlab PAT... help!
Have been using VSCode with Gitlab for a long time, connecting to multiple projects within the same Gitlab account without problems. I have been using the Gitlab Workflow VSCode extension, and set up a PAT to work with that extension some time ago. Recently I got a notification that the PAT ... More on forum.gitlab.com
🌐 forum.gitlab.com
9
0
December 3, 2021
Use of private gitlab with vscode
Problem to solve achieve to connect vscode with gitlab from a private entity and not gitlab.com At the university we have a private gitlab eg. https://gitlab-research.university.eu/ and I want to link it with my vscode so I can pull and push directly from there using the gitlab workflow extension. More on forum.gitlab.com
🌐 forum.gitlab.com
6
1
April 5, 2024
GitLab and Visual Studio Code
Hi. I am having trouble using ‘git push’ to a branch on a project as I keep getting rejected.The owner has given me permission via my GitLab registered mail BUT there seems to be a conflict. VSCode only allows me to Login via its Microsoft page. That email is associated with GitHub. More on forum.gitlab.com
🌐 forum.gitlab.com
3
0
June 6, 2023
Gitlab auth with personal access token
Hi, i’m trying to authenticate via gitlab workflow extension in vsCode? After: adding my username url : https://gitlab.com/usernamehereinput entering my personal access token created in my preferences I’m getting an error that just says “request failed.” Can anyone help? thank you! More on forum.gitlab.com
🌐 forum.gitlab.com
6
0
March 13, 2023
People also ask

Can I use a GitLab project access token?
The VS Code extension documentation specifies a PAT for this authentication flow. Personal, group, and project tokens also differ in reach: a personal token can access resources available to the user, a group token is limited to a group and its projects, and a project token is limited to one project. Use the token type supported by your instance and extension configuration, with the required API permissions.
🌐
cloudspress.com
cloudspress.com › home › guides › featured articles › how to add gitlab access token to vscode
How to Add a GitLab Access Token to VS Code
Where do I paste a GitLab token in VS Code?
Do not paste it into a setting named gitlab.token. Open View &gt; Command Palette, run GitLab: Authenticate, choose the GitLab instance, select PAT, and enter the token when prompted.
🌐
cloudspress.com
cloudspress.com › home › guides › featured articles › how to add gitlab access token to vscode
How to Add a GitLab Access Token to VS Code
What scope does GitLab for VS Code require?
The current GitLab documentation requires the api scope for PAT authentication. It does not list read_user as a required scope for this VS Code flow.
🌐
cloudspress.com
cloudspress.com › home › guides › featured articles › how to add gitlab access token to vscode
How to Add a GitLab Access Token to VS Code
🌐
GitLab
docs.gitlab.com › gitlab docs › use gitlab › manage authentication and authorization › user authentication › gitlab token overview › legacy personal access tokens
Personal access tokens | GitLab Docs
They are an alternative to OAuth2 tokens and are similar to group access tokens and project access tokens, but are attached to a user rather than a group or project. You can use a personal access token to authenticate:
🌐
Itechguides
itechguides.com › home › product reviews › laptop reviews › how to add gitlab access token to vscode
How to Add a GitLab Access Token to VS Code
August 8, 2026 - To connect GitLab features in VS Code, use the GitLab for VS Code extension and its built-in authentication command. The current procedure is not to paste a token into a gitlab.token setting. You need a GitLab personal access token (PAT) with the api scope.
🌐
CloudsPress
cloudspress.com › home › guides › featured articles › how to add gitlab access token to vscode
How to Add a GitLab Access Token to VS Code
August 8, 2026 - ... If you already have an unexpired token with the api scope, you can skip to authentication. Otherwise, create one in GitLab: Sign in to GitLab. Select your avatar, then choose Edit profile.
🌐
Hoop
hoop.dev › blog › add-gitlab-personal-access-token-to-vscode
Add GitLab Personal Access Token to Vscode
3 weeks ago - To add gitlab personal access token to vscode, create a scoped token in GitLab and save it in the editor extension. The editor then uses that secret key to read and write repo data on your behalf.
Find elsewhere
🌐
GoLinuxCloud
golinuxcloud.com › home › devops › git › set up gitlab with visual studio code from scratch
Set up GitLab with Visual Studio Code from Scratch | GoLinuxCloud
August 24, 2022 - Click on your GitLab profile photo -> Edit Profile -> Access Tokens and add a token name, expiry date, and scope, then click on Create personal access token.
🌐
TechBloat
techbloat.com › home › how to add gitlab access token to vscode
How to Add GitLab Access Token to VSCode - TechBloat
January 16, 2026 - Follow this straightforward guide to set up your GitLab token within VSCode effectively. Log into your GitLab account. Navigate to User Settings by clicking on your profile avatar. Select Access Tokens. Specify a Name for your token, set the desired Scopes (e.g., api, read_repository), and ...
🌐
UMA Technology
umatechnology.org › home › how to add gitlab access token to vscode
How to Add GitLab Access Token to VSCode - UMA Technology
May 16, 2026 - You need to clone, pull, and push repositories you personally work on. You want to use the GitLab Workflow extension with your account. A project access token is tied to one project.
🌐
GitLab
forum.gitlab.com › how to use gitlab › vscode + gitlab pat... help!
VSCode + Gitlab PAT... help! - How to Use GitLab - GitLab Forum
December 3, 2021 - Have been using VSCode with Gitlab for a long time, connecting to multiple projects within the same Gitlab account without problems. I have been using the Gitlab Workflow VSCode extension, and set up a PAT to work with that extension some time ago. Recently I got a notification that the PAT was going to expire.
🌐
GitLab
forum.gitlab.com › how to use gitlab › use of private gitlab with vscode
Use of private gitlab with vscode - How to Use GitLab - GitLab Forum
April 5, 2024 - Problem to solve achieve to connect vscode with gitlab from a private entity and not gitlab.com At the university we have a private gitlab eg. https://gitlab-research.university.eu/ and I want to link it with my vscode so I can pull and push directly from there using the gitlab workflow extension.
🌐
Asep Alazhari
asepalazhari.com › home › blog › stop git asking for credentials in vs code
Stop Git Asking for Credentials in VS Code
February 15, 2026 - Getting a token takes about 60 seconds. Navigate to GitLab settings. Find Developer settings at the bottom of the left sidebar. Click Personal access tokens.
🌐
GitLab
forum.gitlab.com › how to use gitlab › gitlab and visual studio code
GitLab and Visual Studio Code - How to Use GitLab - GitLab Forum
June 6, 2023 - Hi. I am having trouble using ‘git push’ to a branch on a project as I keep getting rejected.The owner has given me permission via my GitLab registered mail BUT there seems to be a conflict. VSCode only allows me to Login via its Microsoft page. That email is associated with GitHub.
🌐
Medium
medium.com › @aravind.selvakumar › gitlab-with-visual-studio-fe4a04251bbb
Gitlab with Visual Studio. When Gitlab is your choice of SCM, you… | by Aravind Selvakumar | Medium
September 23, 2023 - Create a project in your GitLab account. Project is a location where you intent to place all your repositories. ... Step 1: Firstly, you need to create a personal access token (PAT). Login to your GitLab account.
🌐
GitLab
forum.gitlab.com › how to use gitlab › self-managed
Gitlab auth with personal access token - Self-managed - GitLab Forum
March 13, 2023 - Hi, i’m trying to authenticate via gitlab workflow extension in vsCode? After: adding my username url : https://gitlab.com/usernamehereinput entering my personal access token created in my preferences I’m getting an …
🌐
Medium
medium.com › @galohernandez › pushing-your-first-project-to-gitlab-can-be-very-tricky-9f18f9a7a504
How to push your Python project to GitLab — the latest way! | by Galo Hernandez | Medium
June 2, 2023 - Here VSCode automatically filled the field with gitlab.com so just ENTER to the next step. Paste in your GitLab personal access token and press Enter.
🌐
Reddit
reddit.com › r/gitlab › setting up a token in vscode wtih gitlab
r/gitlab on Reddit: setting up a token in vscode wtih gitlab
October 12, 2020 -

i have a private repository cloned in vscode from gitlab, but everytime i make a push or pull, it always ask for may username and password, is there a way to add it to the keyring, so that it just ask the keyring password when i ope up vscode ?

i am on linux if that makes a difference thanks .

🌐
GitHub
github.com › fatihacet › gitlab-workflow
GitHub - fatihacet/gitlab-workflow: VSCode extension to enrich your GitLab experience · GitHub
October 5, 2021 - Self-hosted GitLab instance go to "Settings" and click "Access Tokens" on the left navigation menu ... Give a name to your token. Select and expiry date. Select "api" and "read_user" permissions. Hit "Create personal access token" button.
Author: fatihacet
🌐
Visual Studio Marketplace
marketplace.visualstudio.com › items
GitLab Explorer - Visual Studio Marketplace
August 7, 2018 - Extension for Visual Studio Code - VSCode GitLab Explorer Extension to Work with GitLab Project Items like Groups, Projects, Issues etc.