How to clone Azure Repos?
Hello Everyone
Welcome to CloudAffaire and this is Debjeet.
You can clone an Azure repo using HTTPS (With password or personal access token) or SSH endpoints. In this blog post, we will discuss different ways of cloning an Azure repository in your local system.
How to clone Azure Repos?
Prerequisites:
Clone Azure Repo using HTTPS with Password:
Step 1: Login to your Azure DevOps account using below link
https://dev.azure.com/your_organization_name
Step 2: Navigate to Azure repo under your project.
Azure DevOps Organization => Project => Repos => Files
Select the HTTPS endpoint and click ‘Generate Git Credentials”.
Step 3: Copy the generated credentials and store it in a safe place. Also copy the HTTPS clone URL.
Step 4: Open your favorite terminal and type below git command to clone the repository.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
## Clone an Azure DevOps repository git clone https://dev.azure.com/ ## Cloning into ' ## Password for 'https:// ## warning: You appear to have cloned an empty repository. ## Create your 1st commit cd echo "hello world" > README.md git add . git commit -m "README.md added" ## Push your changes to Azure DevOps repos git push ## Password for 'https:// ## Enumerating objects: 3, done. ## Counting objects: 100% (3/3), done. ## Writing objects: 100% (3/3), 259 bytes | 259.00 KiB/s, done. ## Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 ## remote: Analyzing objects... (3/3) (4 ms) ## remote: Storing packfile... done (130 ms) ## remote: Storing index... done (61 ms) ## To https://dev.azure.com/ ## * [new branch] master -> master |
If you refresh your Azure repo page, you will be able to see the file now that we just pushed.
Clone Azure Repo using HTTPS with Personal Access Token:
Step 1: Generate a personal access token in your Azure DevOps account.
https://cloudaffaire.com/how-to-create-a-personal-access-token-pats-in-azure-devops/
Step 2: Clone Azure Repo using Personal Access Token (PAT).
1 2 3 |
MY_PAT=yourPAT # replace "yourPAT" with your actual PAT B64_PAT=$(printf "%s"":$MY_PAT" | base64) git -c http.extraHeader="Authorization: Basic ${B64_PAT}" clone https://dev.azure.com/ |
Clone Azure Repo using SSH:
Step 1: Generate SSH keys for Azure Repos using ssh-keygen.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
## Open terminal and execute below command ssh-keygen -t rsa -b 2048 -C "cloudaffaire@gmail.com" ## Generating public/private rsa key pair. ## Enter file in which to save the key (/home/ ## Enter passphrase (empty for no passphrase): ## Enter same passphrase again: ## Your identification has been saved in azure_repo. ## Your public key has been saved in azure_repo.pub. ## The key fingerprint is: ## SHA256:9uK1kxXD9Us5JYWwAxZTB5sEDugx9vXIb8AH/7V7J2s cloudaffaire@gmail.com ## The key's randomart image is: ## +---[RSA 2048]----+ ## | .. %+=o.o.| ## | = +o+ =+ .| ## | o+ +.*=. oo| ## | . . = D. +o| ## | M + +..+| ## | . . + .o | ## | . o+ .| ## | . oo. Z.o| ## | . .. ..oo| ## +----[SHA256]-----+ ## Add non default ssh key in the config file cat << EOF >> ~/.ssh/config # Account- azure - cloudaffaire Host ssh.dev.azure.com IdentityFile ~/.ssh/azure_repo IdentitiesOnly yes EOF |
Step 2: Copy the content of the public key
1 2 |
## Copy the content of public key cat /home/ |
Step 3: Login to your Azure DevOps account using below link
https://dev.azure.com/your_organization_name
Step 4: Click on the user setting icon on the top right corner and then click on “SSH Public Key”.
Step 5: Click on the “New Key” button to add the public ssh key.
Step 6: Give a name to the public ssh key and copy the content of your public ssh key in the “Public Key Data” section (Copied in step 2) and click “Add”.
Step 7: Switch back to the terminal and execute below command to clone your Azure repo using SSH key.
1 2 3 4 |
## Clone the Azure repo using ssh git clone git@ssh.dev.azure.com:v3/ ## Are you sure you want to continue connecting (yes/no)? yes |
Note: You can get the SSH clone URL from your Azure repo inside your project.
Hope you have enjoyed this article. To know more about Azure DevOps, please refer below official documentation
https://docs.microsoft.com/en-us/azure/devops/?view=azure-devops