Help: Visual Studio Code keeps prompting me to login, or how to update your git remote origin with a new PAT

Sebastian Rogers
2 min readOct 27, 2022

--

TL;DR If you are using Personal Access Tokens (PATs) with Git and Azure DevOps then when a PAT expires git will keep prompting you to log in, so update the remote origin’s URL with a valid PAT and it will all work again.

This happened to one of the Azure DevOps engineers today. He kept getting prompted to log into git from Visual Studio Code but only for one of his projects.

He connects to Git by using clone in Azure DevOps and telling it to generate credentials. Behind the scenes this creates a Personal Access Token (PAT) valid for six months only. When that six months expires then git can no longer connect.

To solve this, you need to either extend the validity of the PAT, not possible for generated credentials, or replace the PAT with a valid one.

This is very easy from the git command line.

Get or generate a valid PAT then

git remote set-url origin https:<PAT>@dev.azure.com/<Organisation>/<Project>/_git<Repo>

Working that out is a bit hard here’s a helper script that will do it all for you:

Then just pull and push as normal

TL;CR If you are using Personal Access Tokens (PATs) with Git and Azure DevOps then when a PAT expires git will keep prompting you to log in, so update the remote origin’s URL with a valid PAT and it will all work again.

--

--

Sebastian Rogers
Sebastian Rogers

Written by Sebastian Rogers

Technical Director for Simple Innovations Ltd. First paid for code in 1980, but still has all his own hair.

No responses yet