DevOps | Scripts | Automation

Azure DevOps

How to clone Azure DevOps Repo with PAT?

Overview

In the previous article, we have gone through how we can clone ADO (Azure DevOps) repo with the https and SSH methods. In this article, we will cover how to clone the ADO repo with the Personal Access Token (PAT).

Cloning the ADO repo with the PAT is super easy. For that, we first need to generate a PAT token through Azure DevOps and provide appropriate permission on the repo.

Generating PAT

  • To generate PAT, click on “User Settings” on the ADO page.
  • Once you select the PAT, provide the expiry date for the token and the permission to access the repository. For this example, we have provided full permission to the code repository and click on Create button.
  • PAT will be generated as shown below. Store it in a safe place because you can’t retrieve same for the second time.
  • Now open the project repository and click on Clone and copy the https repository URL.

Your URL will be something like,

https://{username}@dev.azure.com/{OrganizationName}/{ProjectName}/_git/{ProjectName}

You need to append the PAT to the above URL,

https://{username}:{PAT}@dev.azure.com/{OrganizationName}/{ProjectName}/_git/{ProjectName}

For Example,

https://chiragnagrekar:kpuhe3g7aaqu2eea4pfsbgkp992203330@dev.azure.com/chiragnagrekar/theAutomationCode/_git/theAutomationCode

Now just clone with the above URL,

git clone https://chiragnagrekar:kpuhe3g7aaqu2eea4pfsbgkp992203330@dev.azure.com/chiragnagrekar/theAutomationCode/_git/theAutomationCode

The above command will clone the Git repository. However, still, the best approach is to use HTTPS and SSH-based repositories.

Loading