Events
17 Mar, 9 pm - 21 Mar, 10 am
Join the meetup series to build scalable AI solutions based on real-world use cases with fellow developers and experts.
Register nowThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Azure DevOps Services | Azure DevOps Server 2022 | Azure DevOps Server 2020
This guide shows you how to share your code in a Git repo in Azure Repos using the command line.
The instructions in this article use the default bash shell used on Linux and macOS, but the Git commands work in any shell, including Git Bash from Git for Windows.
Category | Requirements |
---|---|
Project access | Member of a project. |
Permissions | - View code in private projects: At least Basic access. - Clone or contribute to code in private projects: Member of the Contributors security group or corresponding permissions in the project. - Set branch or repository permissions: Manage permissions permissions for the branch or repository. - Change default branch: Edit policies permissions for the repository. - Import a repository: Member of the Project Administrators security group or Git project-level Create repository permission set to Allow. For more information, see Set Git repository permissions. |
Services | Repos enabled. |
Tools | Optional. Use az repos commands: Azure DevOps CLI. |
Note
In public projects, users with Stakeholder access have full access to Azure Repos, including viewing, cloning, and contributing to code.
Install the Azure CLI. At least v2.0.49
, which you can verify with az --version
command.
Add the Azure DevOps Extension az extension add --name azure-devops
Run the az login
command.
If the CLI can open your default browser, it does so and loads a sign-in page. Otherwise, you need to open a browser page and follow the instructions on the command line to enter an authorization code after navigating to https://aka.ms/devicelogin in your browser. For more information, see the Azure CLI login page.
For seamless commanding, set the organization and project as defaults in configuration.
az devops configure --defaults organization=https://dev.azure.com/contoso project=contoso
Download and install Git for Windows , which includes the Git Credential Manager to easily connect to Azure Repos.
Use Homebrew to install and set up Git.
brew install git
To download and install Git, use your distribution's package management system. For example, on Ubuntu:
sudo apt-get install git
Refer to the list of install commands for the most up-to-date instructions for your Linux distribution.
Create a local Git repo for your code. If your code is already in a local Git repo, you can skip this step.
Navigate to the folder where your code is on the command line:
cd /home/fabrikam/fiber
Create a Git repo on your machine to store your code. You'll connect this repo to Azure Repos in the next section.
git init .
Commit your code into the local Git repo.
git add --all
git commit -m "first commit of my code"
Create a new Git repo in Azure Repos for your code.
az repos create --name FabrikamApp
Copy the clone URL from the remote URL attribute in the JSON output.
$ az repos create --name FabrikamApp
[
{
"defaultBranch": null,
"id": "fa3ee42f-519d-4633-8e31-4a84de343ca3",
"isFork": null,
"name": "FabrikamApp",
"parentRepository": null,
"project": {
"abbreviation": null,
"description": "This is the pipeline project for github repo",
"id": "fa3ee42f-519d-4633-8e31-4a84de343ca4",
"lastUpdateTime": "2019-04-09T08:32:15.977Z",
"name": "Fabrikam",
"revision": 255,
"state": "wellFormed",
"url": "https://dev.azure.com/fabrikops2/_apis/projects/fa3ee42f-519d-4633-8e31-4a84de343ca4",
"visibility": "public"
},
"remoteUrl": "https://dev.azure.com/fabrikops2/Fabrikam/_git/FabrikamApp",
"size": 0,
"sshUrl": "fabrikops2@vs-ssh.visualstudio.com:v3/fabrikops2/Fabrikam/FabrikamApp",
"url": "https://dev.azure.com/fabrikops2/fa3ee42f-519d-4633-8e31-4a84de343ca4/_apis/git/repositories/fa3ee42f-519d-4633-8e31-4a84de343ca3",
"validRemoteUrls": null
}
]
Connect your local repo to the Git repo in Azure Repos using the copied clone URL in the git remote
command:
git remote add origin https://dev.azure.com/fabrikops2/Fabrikam/_git/FabrikamApp
Before pushing your code, set up authentication with credential managers or SSH before continuing.
git push origin main
Events
17 Mar, 9 pm - 21 Mar, 10 am
Join the meetup series to build scalable AI solutions based on real-world use cases with fellow developers and experts.
Register nowTraining
Module
Manage changes to your Bicep code by using Git - Training
Learn how to use Git version control with your Bicep files and infrastructure as code.
Certification
Microsoft Certified: DevOps Engineer Expert - Certifications
This certification measures your ability to accomplish the following technical tasks: Design and implement processes and communications, design and implement a source control strategy, design and implement build and release pipelines, develop a security and compliance plan, and implement an instrumentation strategy.
Documentation
Clone an existing Git repo - Azure Repos
Learn how to create a local clone of any remote Git repo using Visual Studio or the Git command line.
Connect to your Git repos using credential managers - Azure Repos
Authenticate to Azure Repos and TFS Git repos using credential managers
Git clone or Git push fails to an Azure DevOps repository - Azure DevOps
This article discusses problems that might occur when you try to perform Git clone or Git push function to an Azure DevOps repository.