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
🌐
Visual Studio Code
code.visualstudio.com › docs › sourcecontrol › github
Work with GitHub in VS Code
October 7, 2026 - You don't need an extension to authenticate Git operations with GitHub. When you clone a private repository or push to a GitHub repository, VS Code prompts you to sign in.
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

please help me I'm going insane
Did you by any chance notice that in the background, your browser opens with the GitHub page and a login? That's what should happen while that little popup shows up - staring at it won't sign you in. More on reddit.com
🌐 r/vscode
16
14
February 12, 2025
windows - Cannot sign in with GitHub in VSCode - Stack Overflow
I'm having trouble with signing in GitHub in VSCode on Windows. When i attempt to Sign in with GitHub to use GitHub Pull Requests and Issues', it get's stuck with the status showing: 'Signing in to github.com...' The GitHub Authentication output shows: 2024-02-27 10:54:46.102 [info] Logging ... More on stackoverflow.com
🌐 stackoverflow.com
How to connect my GitHub Enterprise Account with Visual Studio Code - Stack Overflow
If you have the GitHub Actions ... above under relevant extension, it could have been renamed to "GHE.com & GitHub Enterprise Server Authentication"). For the changes to take effect, restar VSCode, next time you're asked to login you should be redirected to your enterprise ... More on stackoverflow.com
🌐 stackoverflow.com
git - Re-enable Visual Studio Code GitHub authentication - Stack Overflow
PS: I have the GitHub Copilot Git extension enabled and it’s authenticated properly in Git (properly working) ... 1. which "VSCode git-scm" plugin do you mean? (there are like hundreds) 2. git or github ? More on stackoverflow.com
🌐 stackoverflow.com
🌐
Baeldung
baeldung.com › home › git › adding git credentials in vs code
Adding Git Credentials in VS Code | Baeldung on Ops
April 30, 2025 - After that, Git prompts for credentials. When it asks for a password, we paste the Personal Access Token instead. Subsequently, GitHub should recognize the token in place of the usual password and successfully authenticate the user.
🌐
GitHub
vscode-auth.github.com
GitHub for VS Code
We've made some updates to our authentication process for VS Code and GitHub.
🌐
DEV Community
dev.to › kougou › how-to-connect-vscode-to-github-1nip
How to Connect VSCode to GitHub - DEV Community
April 8, 2025 - A browser window will open with the GitHub authentication page. Log in and authorize access. Once authentication is successful, VSCode will be connected to your GitHub account!
🌐
GitHub
github.com › tekumara › notes › blob › main › vscode-github-auth.md
notes/vscode-github-auth.md at main · tekumara/notes · GitHub
If GitHub for VSCode has not already been authorised your account, you'll be asked to authorise it. Click Authorise github · On the Success page popup click Open Visual Studio Code to be taken back to VS Code. When VS Code asks Allow an extension to open this URI? click Allow. Once complete, the Github Authentication process generates the keychain item vscodevscode.github-authentication which is used to generate session tokens.
🌐
Reddit
reddit.com › r/vscode › please help me i'm going insane
r/vscode on Reddit: please help me I'm going insane
February 12, 2025 -

EDIT: SOLVED!!!

Here's the post: https://www.reddit.com/r/github/comments/1inrerx/please_help_me_im_going_insane/

thanks for every one that contributed to ending this nightmare.

I have been trying to sign in to GitHub from vscode for about two weeks now and to no avail

I believe I have tried everything, searched the web for similar issues but for the first time no one had a similar issue, I have tried every AI chat there is, Gpt, deep seek, even copilot on github's website but nothing.

the issue looks very simple which is why it has dumbfounded me so much.

here's how it goes: vscode says I have to sign in to github to use associated features like copilot or to save my code in a repository, but when I do a pop up appears on the bottom right that says signing in to github.

I have stared at this pop up for longer than I can admit.

eventually after a couple minutes it says I haven't finished configuring the authenticator extension or something and says it will try to sign in using a local host, another half an hour and after it fails, gives me a code to past on the website to sign in, I do that and it says your all set, returning to vs code reveals that I am indeed not all set. as it gives me an "Error signing in to github" "try again" in a smug way

at first I thought nothing of it and it wasn't a big deal until a couple of days ago when I lost a big chunk of a project I've been working on for my collage

I'm so frustrated with every thing about this as no one seems to relate and I feel like the only one with this issue

I saw a post on stackoverflow for someone with what he described to be a similar issue to mine but no one seemed to know why and no solution to the problem was posted

here's a bunch of things I tried to do but didn't work

  1. I'm working from home so no firewall or vpn or anything similar to try and block the extension I think.

  2. tried to manually sign in using github from the terminal by configuring my user name and email. still nothing.

  3. cleared any previous credentials stored on the extension if there was any since it didn't work once. nope. not it.

  4. uninstall and reinstall, multiple times, nah.

  5. use the token, most AI bots suggested, I don't have two factor authentication but still tried it, nothing.

  6. made sure I was signed in to github on my browser before trying any of these by the way,

  7. reinstall vs code because why not, god damnit.

  8. check developer tools console for any warnings or errors for the network, you guessed it.

I would give my hand and or leg for any clue about this as it no longer is about saving my code from withering away due to power outages but is now about my dignity and self respect as a junior developer.

help me please.

Find elsewhere
🌐
Visual Studio Code
code.visualstudio.com › docs › sourcecontrol › faq
Source control FAQ
1 week ago - Use Git Credential Manager, the recommended Git credential helper for Windows, macOS, and Linux. Git for Windows includes Git Credential Manager. Yes. VS Code supports authentication with GitHub Enterprise Server.
🌐
Rune Hub
rune.codes › home › tutorials › vs code › how to sign in to github from vs code
How to Sign In to GitHub from VS Code | Rune Hub
August 1, 2026 - The sign-in flow opens your browser, asks you to authorize VS Code, and sends you back to the editor. You do not need to copy tokens manually. Authentication is triggered automatically when you perform an action that needs GitHub access.
🌐
Open VSX Registry
open-vsx.org › extension › vscode › github-authentication
github-authentication – Open VSX Registry
An open source, vendor-neutral registry for VS Code–compatible extensions · Copyright © Eclipse Foundation, AISBL. All Rights Reserved
🌐
TMS Outsource
tms-outsource.com › home › how to connect to a github repository from vs code
How to Connect to a GitHub Repository From VS Code
August 26, 2026 - Sign-out and sign-in steps: Click the Accounts icon in the bottom-left activity bar · Select the signed-in GitHub account and choose “Sign Out” · Click “Sign in with GitHub” and authenticate the second account via the browser OAuth flow ·
🌐
TMS Outsource
tms-outsource.com › home › how to connect vscode to github easily
How to Connect VSCode to GitHub Easily
September 3, 2026 - 2. Select “Sign in to Sync Settings” > Choose “Sign in with GitHub” · 3. Browser opens > Click “Authorize Visual-Studio-Code” · 4. Return to VSCode > Confirm “You are signed in” notification · This establishes token-based authentication between VSCode and GitHub...
🌐
Azurecodingarchitect
azurecodingarchitect.com › posts › gitcredentials
Note to self: fix invalid GitHub credentials in VSCode | Azure Coding Architect
Open an command line (powershell or bash), navigate to your local repo folder and enter the command: git config --global credential.helper manager-core · Re-run git pull and follow the pop-up instructions to authenticate in a browser (which ...
🌐
Awsm
awsm.page › git › use-github-with-ssh-complete-guide-including-vscode-setup
Use GitHub with SSH - Complete guide including VSCode setup
To do so: Start the ssh-agent in the background, using the command ... VS Code works automatically when you have SSH keys without a passphrase. Or if your ssh-agent is enabled, and you have entered at least once your passphrase.
🌐
GitHub
docs.github.com › en › codespaces › developing-in-a-codespace › using-github-codespaces-in-visual-studio-code
Using GitHub Codespaces in Visual Studio Code - GitHub Docs
You can develop in your codespace directly in Visual Studio Code by connecting the GitHub Codespaces extension with your GitHub account.
Top answer
1 of 16
250

Why does Visual Studio Code ask for a password? Because Visual Studio Code runs the auto-fetch feature, while the Git server doesn't have any information to authorize your identity. It happens when:

  • Your Git repository has a https remote URL. Yes! This kind of remote will absolutely ask you every time. No exceptions here! (You can do a temporary trick to cache the authorization as the solution below, but this is not recommended.)
  • Your Git repository has ssh remote URL, but you've not copied your ssh public key onto the Git server. Use ssh-keygen to generate your key and copy it to Git server. Done! This solution also helps you never retype password on terminal again. See a good instruction by @Fnatical here for the answer.

The updated part at the end of this answer doesn't really help you at all. (It actually makes you stagnant in your workflow.) It only stops things happening in Visual Studio Code and moves these happenings to the terminal.

Sorry if this bad answer has affected you for a long, long time.


The original answer (bad)

I found the solution on Visual Studio Code document:

Tip: You should set up a credential helper to avoid getting asked for credentials every time VS Code talks to your Git remotes. If you don't do this, you may want to consider Disabling Autofetch in the ... menu to reduce the number of prompts you get.

So, turn on the credential helper so that Git will save your password in memory for some time. By default, Git will cache your password for 15 minutes.

In Terminal, enter the following:

git config --global credential.helper cache
# Set Git to use the credential memory cache

To change the default password cache timeout, enter the following:

git config --global credential.helper 'cache --timeout=3600'
# Set the cache to timeout after 1 hour (setting is in seconds)

If the original answer doesn't work

I installed Visual Studio Code and configuration same above, but as @ddieppa said, It didn't work for me too. So I tried to find an option in User Setting, and I saw "git.autofetch" = true, now set it's false! Visual Studio Code is no longer required to enter password repeatedly again!

In menu File → Preferences → User Setting: Type these:

Place your settings in this file to overwrite the default settings:

{
  "git.autofetch": false
}
2 of 16
219

This has been working for me:

  1. Set the credential helper to store:

    git config --global credential.helper store

  2. Then verify if you want:

    git config --global credential.helper

A simple example when using Git Bash quoted from here (works for the current repository only, use --global for all repositories):

git config credential.helper store
git push http://example.com/repo.git

Username: < type your username >
Password: < type your password >

[several days later]

git push http://example.com/repo.git

[your credentials are used automatically]

It will work for Visual Studio Code too.

A more detailed example and advanced usage is here.

Note: Username and passwords are not encrypted and are stored in plain text format, so use it on your personal computer only.