How to update an Azure DevOps PAT in GitHub

A while back, I blogged about using Azure DevOps to automate pushing file changes to a DR copy of our Azure Web App. One part of this setup process requires setting up a Personal Access Token in Azure DevOps so that your automated process can access Azure DevOps and write the changes to Azure DevOps.

The catch to setting this up is that it needs to be updated every year or so, as the Personal Access Token (also called a PAT) has a finite lifetime and needs to be refreshed occasionally. Thankfully, this is a pretty easy process. To start with, you’ll need to get your new PAT from Azure DevOps. To do this, log in to https://dev.azure.com and then select the icon of a person with a little gear in front of them in the upper right corner (next to your Entra ID picture). Then select Personal Access Token from the menu.

This will list all the Personal Access Tokens you have created, as well as when they expire.

Check the box next to the token that you are using for git (in my case it is the one named “Git”) and then click the button that says Regenerate. This will give you your new token. Make a note of this token as you’ll need it in the next step.

Use webssh to connect to the Web App that is running your website.

You’ll need to know the name of the git alias that is used to connect to your DevOps repo. In my examples, I use the alias “DevOps,” but you may have a different alias configured.

Updating the PAT is pretty straightforward; simply run the below command with the sections in {} replaced with their actual values.

git remote set-url DevOps https://{New-PAT}@dev.azure.com/{Org}/{Project}/_git/{Repo}

Once that is done, you can do a git push to push your changes to DevOps and your disaster recovery site. I’d also recommend setting up a calendar appointment a few days before your PAT expires to get a new one configured so that your git updates don’t break the next time your PAT expires.

Denny

Share

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Trust DCAC with your data

Your data systems may be treading water today, but are they prepared for the next phase of your business growth?