Follow these simple steps to set up GitHub authentication with a personal access token:
Open a command line window on your PC or Terminal on Mac
Set the current directory to your project root
cd C:\Users\Giddy\source\repo\MySampleProjectRun the command to set remote access via a token
git remote set-url origin https://username:token@github.com/username/repository.gitExample:
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:
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).
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.
- Press
If you still want to update your remote manually with the token (not recommended for long-term use):
Use with AI
git remote set-url origin https://<USERNAME>@github.com/<USERNAME>/<REPOSITORY>.gitThen 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.
Follow these simple steps to set up GitHub authentication with a personal access token:
Open a command line window on your PC or Terminal on Mac
Set the current directory to your project root
cd C:\Users\Giddy\source\repo\MySampleProjectRun the command to set remote access via a token
git remote set-url origin https://username:token@github.com/username/repository.gitExample:
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:
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).
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.
- Press
If you still want to update your remote manually with the token (not recommended for long-term use):
Use with AI
git remote set-url origin https://<USERNAME>@github.com/<USERNAME>/<REPOSITORY>.gitThen 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.
Tested on Visual Studio Code (Mac)
no need for an extra extension. I only trust official extensions, sorry. GitHub extension by KnisterPeter
- Generate a personal access token from github.com
- Make sure to save your access token (e.g., ghp_pVC*****)
- Open your project with Visual Studio Code or navigate to your project in the terminal,
cd ~/path/to/your/project - 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 - 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)
please help me I'm going insane
windows - Cannot sign in with GitHub in VSCode - Stack Overflow
How to connect my GitHub Enterprise Account with Visual Studio Code - Stack Overflow
git - Re-enable Visual Studio Code GitHub authentication - Stack Overflow
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
-
I'm working from home so no firewall or vpn or anything similar to try and block the extension I think.
-
tried to manually sign in using github from the terminal by configuring my user name and email. still nothing.
-
cleared any previous credentials stored on the extension if there was any since it didn't work once. nope. not it.
-
uninstall and reinstall, multiple times, nah.
-
use the token, most AI bots suggested, I don't have two factor authentication but still tried it, nothing.
-
made sure I was signed in to github on my browser before trying any of these by the way,
-
reinstall vs code because why not, god damnit.
-
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.
I had the same issue because my network is behind a corporate firewall. Solved it by going to settings.json in VS Code and setting the proxy:
"http.proxy": "http://username:password@proxyhost:value"
From https://github.com/microsoft/vscode/issues/111824
In my case, I just had to set a web browser as default in the system settings and then i successfully logged in.
I have set it up in the vscode settings like so:

Then it asked for my personal access token. This is token can be created under "settings" -> "developer options" see: https://docs.github.com/en/enterprise-server@3.4/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token
2026 update (VSCode version 1.108.0):
If you have the GitHub Actions extensions installed go to Settings>Extensions>GitHub Actions and there you will see the checkbox "Use-enterprise" (obviously for this to work the enterprise URI has to be configured as shown 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 login.
Here's what worked for me on vs code 1.62.3.
Clone the GitHub Enterprise repo outside of vs code (ie, using git cli in a terminal or GitHub Desktop).
In vs code, open the folder containing the cloned repo.
And just like magic, it works. If you click on the source control tab in vs code, you can pull changes and make commits. Actually, it might not work quite yet if your cloned project doesn't have your personal access token saved. If you need to do that, you can find instructions in this answer to a different question
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
httpsremote 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
sshremote URL, but you've not copied your ssh public key onto the Git server. Usessh-keygento 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
}
This has been working for me:
Set the credential helper to store:
git config --global credential.helper storeThen 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.
From Github VSCode Docs:
GitHub authentication for GitHub repositories
VS Code now has automatic GitHub authentication against GitHub repositories. You can now clone, pull, push to and from public and private repositories without configuring any credential manager in your system. Even Git commands invoked in the Integrated Terminal, for example git push, are now automatically authenticated against your GitHub account.
You can disable GitHub authentication with the git.githubAuthentication setting. You can also disable the terminal authentication integration with the git.terminalAuthentication setting.
UPDATE: Refer to the solution here
While it may not be the case for you, cloning from the https rather than the ssh is often the source of issues like this one.
Instructions for setting up SSH keys to GitHub:
https://help.github.com/en/github/authenticating-to-github/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent
Setting up the connection details inside VSCode may interfere with using git from a terminal outside of it.