Events
Mar 17, 9 PM - Mar 21, 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 2019
Share your code with others in Azure DevOps when you use a Git repository.
Category | Requirements |
---|---|
Project access | Project member. |
Git command-line tool | One of the following Git command-line tools: - Git for Windows and Git Credential Manager. - Git for macOS or Linux. For macOS and Linux, we recommend that you configure SSH authentication. |
To work with a Git repo, clone it to your computer, which creates a complete local copy of the repo. Your code might be in one of several places.
Complete the following step that's applicable to your scenario:
From your web browser, open the team project for your organization and select Repos > Files.
Select Clone.
Copy the URL.
Open the Git command window (Git Bash on Git for Windows). Go to the folder where you want the code from the repo stored on your computer, and run git clone
, followed by the path copied from Clone URL in the previous step. See the following example:
git clone https://FabrikamFiber01@dev.azure.com/FabrikamFiber01/FabrikamFiber01-01/_git/FabrikamFiber01-01
Git downloads a copy of the code, including all commits, and branches from the repo, into a new folder for you to work with.
Switch your directory to the repository that you cloned.
cd fabrikam-web
Keep this command window open to work in a branch.
Git branches isolate your changes from other work being done in the project. We recommend using the Git workflow, which uses a new branch for every feature or fix that you work on. For our examples, we use the branch, users/jamal/feature1
.
Create a branch with the branch
command.
git branch users/jamal/feature1
This command creates a reference in Git for the new branch. It also creates a pointer back to the parent commit so Git can keep a history of changes as you add commits to the branch.
If you're working with a previously cloned repository, ensure you checked out the right branch (git checkout main
) and that it's up to date (git pull origin main
) before you create your new branch.
Use checkout
to switch to that branch.
git checkout users/jamal/feature1
Git changes the files on your computer to match the latest commit on the checked-out branch.
Tip
When you create a branch from the command line, the branch is based on the currently checked-out branch. When you clone the repository, the default branch (typically main
) gets checked out. Because you cloned, your local copy of main
has the latest changes.
git checkout main
git pull origin main
git branch users/jamal/feature1
git checkout users/jamal/feature1
You can replace the first three commands in the previous example with the following command, which creates a new branch named users/jamal/feature1
based on the latest main
branch.
git pull origin main:users/jamal/feature1
Switch back to the Git Bash window that you used in the previous section. Run the following commands to create and check out a new branch based on the main branch.
git pull origin main:users/jamal/feature1
git checkout feature1
In the following steps, we make a change to the files on your computer, commit the changes locally, and then push the commit to the repo stored on the server.
Browse to the folder on your computer where you cloned the repo, open the README.md
file in your editor of choice, and make some changes. Then, Save and close the file.
In the Git command window, go to the contoso-demo
directory by entering the following command:
cd contoso-demo
Commit your changes by entering the following commands in the Git command window:
git add .
git commit -m "My first commit"
The git add .
command stages any new or changed files, and git commit -m
creates a commit with the specified commit message.
Check which branch you're working on before you commit, so that you don't commit changes to the wrong branch. Git always adds new commits to the current local branch.
Push your changes to the Git repo on the server. Enter the following command into the Git command window:
git push origin users/jamal/feature1
Your code is now shared to the remote repository, in a branch named users/jamal/feature1
. To merge the code from your working branch into the main
branch, use a pull request.
Pull requests combine the review and merge of your code into a single collaborative process. After you’re done fixing a bug or new feature in a branch, create a new pull request. Add the members of the team to the pull request so they can review and vote on your changes. Use pull requests to review works in progress and get early feedback on changes. There’s no commitment to merge the changes because you can abandon the pull request at any time.
The following example shows the basic steps of creating and completing a pull request.
Open the team project for your organization in your web browser and select Repos > Files. If you kept your browser open after getting the clone URL, you can just switch back to it.
Select Create a pull request in the upper-right corner of the Files window. If you don't see a message like You updated users/jamal/feature1 just now, refresh your browser.
New pull requests are configured to merge your branch into the default branch, which in this example is main
. The title and description are prepopulated with your commit message.
You can add reviewers and link work items to your pull request.
You can review the files included in the pull request at the bottom of the New Pull Request window.
Select Create.
View the details of your pull request from the Overview tab. You can also view the changed files, updates, and commits in your pull request from the other tabs.
Select Complete to begin the process of completing the pull request.
Select Complete merge to complete the pull request and merge your code into the main
branch.
Note
This example shows the basic steps of creating and completing a pull request. For more information, see Create, view, and manage pull requests.
Your changes are now merged into the main
branch, and your users/jamal/feature1
branch is deleted on the remote repository.
Switch back to the web portal and select History from the Code page to view your new commit.
Switch to the Files tab, and select the README file to view your changes.
To delete your local copy of the branch, switch back to your Git Bash command prompt and run the following command:
git checkout main
git pull origin main
git branch -d users/jamal/feature1
This action completes the following tasks:
git checkout main
command switches you to the main
branch.git pull origin main
command pulls down the latest version of the code in the main branch, including your changes and the fact that users/jamal/feature1
was merged.git branch -d users/jamal/feature1
command deletes your local copy of that branch.Events
Mar 17, 9 PM - Mar 21, 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
Connect to project from browser/supported client - Azure DevOps
Learn how to connect a browser or client, like Visual Studio, to a project in Azure DevOps.
Create a new Git repo in your project - Azure Repos
Create a new Git repo in an Azure DevOps project via the web portal.
Sign up for Azure Repos - Azure DevOps
How to sign up for Azure Repos.