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)
VSCode + Gitlab PAT... help!
Use of private gitlab with vscode
GitLab and Visual Studio Code
Gitlab auth with personal access token
Can I use a GitLab project access token?
Where do I paste a GitLab token in VS Code?
What scope does GitLab for VS Code require?
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 .