Azure DevOps Services | Azure DevOps Server 2022 - Azure DevOps Server 2019
Visual Studio 2019 | Visual Studio 2022
Get started with developing your code using Azure Repos and Git repositories. You can use Visual Studio or Git commands to clone a repository, define local branches, commit and push changes, and sync with others. If you need to create or import a repository, see Create a new Git repo in your project or Import a Git repository.
Piezīme
This article describes how to use Visual Studio to manage Azure Repos Git repositories. Using similar procedures, you can use Visual Studio to manage GitHub repositories. To clone a GitHub repository, get the URL as described in Cloning a repository.
Visual Studio 2019 version 16.8 and later versions provide a new Git menu for managing the Git workflow with less context switching than Team Explorer. Procedures provided in this article under the Visual Studio tab provide information for using the Git experience as well as Team Explorer. For more information, see Side-by-side comparison of Git and Team Explorer.
- 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.
- View code: At least Basic access. - Clone or contribute to code: Member of the Contributors security group or corresponding permissions in the project.
You can clone a remote Git repository to create a local copy of it. Cloning creates both a copy of the source code for you to work with and version control information so Git can manage the source code.
If you prefer to create a local repository without cloning, see Create a new Git repo. After creating your local repository you can proceed to commit, share, and sync your work.
Visual Studio 2022 provides a Git version control experience by using the Git menu, Git Changes, and through context menus in Solution Explorer. Visual Studio 2019 version 16.8 also offers the Team Explorer Git user interface. For more information, see the Visual Studio 2019 - Team Explorer tab.
From the Git menu on the menu bar, choose Clone Repository...
In the Clone a repository window, enter the remote repo location and the folder path for the cloned repo. If you don't know the remote repo location, select Azure DevOps from Browse a repository options.
Select Clone. After you’ve cloned a Git repository, Visual Studio detects the repository and adds it to your list of Local Repositories in the Git menu.
Visual Studio 2019 provides a Git version control experience by using the Git menu, Git Changes, and through context menus in Solution Explorer.
From the Git menu on the menu bar, choose Clone Repository...
In the Clone a repository window, enter the remote repo location and the folder path for the cloned repo. If you don't know the remote repo location, select Azure DevOps from Browse a repository options.
Select Clone. After you’ve cloned a Git repository, Visual Studio detects the repository and adds it to your list of Local Repositories in the Git menu.
Visual Studio 2019 version 16.8 and later versions provides a Git version control experience while maintaining the Team Explorer Git user interface. You can exercise Git features from either interface interchangeably.
Piezīme
One advantage of connecting to a project through Team Explorer is you gain access to the Work Items hub. For an overview of Team Explorer features, see Navigate in Visual Studio Team Explorer.
In Team Explorer, select Connect to open the Connect page, and then choose Manage Connections > Connect to Project.
In the Connect to a Project window, choose the repo you want to clone and select Clone. If you don't see your repo, select Add Azure DevOps Server to add a server that hosts a repo. You can filter the list to find your repo.
Verify the location for the cloned repo on your computer, and then select Clone.
Open the Azure DevOps Services web portal in your browser by going to https://<your account name>.visualstudio.com.
Open the Azure DevOps Services web portal in your browser by navigating to https://<your account name>.visualstudio.com and find your Git repository. Copy the clone URL from the Clone pop-up.
Git downloads and creates your own copy of the code in a new folder for you.
Commit your work
Git branches isolate your changes from other work in the project.
The recommended Git workflow is to use a new branch for every feature or fix you work on.
You make commits in your local Git repository to save your changes on that branch.
From the Git menu on the menu bar, choose New Branch... to open the Create a new branch window.
In the Create a new branch window, enter a descriptive branch name to let others know what work the branch contains. By default, Visual Studio creates your new branch from the current branch. The Checkout branch checkbox automatically switches you to the newly created branch. Select Create.
Add a README.md file to your cloned repo. In Solution Explorer, you can browse the repo contents using Folder View or open Visual Studio solutions in the repo. Git tracks changes made both inside and outside of Visual Studio.
When you're satisfied with your changes, save them in Git using a commit. In the Git Changes window, enter a message that describes the changes, and then select Commit All. Commit All commits unstaged changes and skips the staging area. You can choose to stage all files before committing by selecting the stage all + (plus) button at the top of the Changes section in the Git Changes window.
Select the commit information link to get further details about the commit.
Piezīme
If you have multiple files and you don't want to commit them all, you can right-click each file and choose Stage. When you've staged all the files you'd like to commit, select Commit Staged. Commit Staged replaces Commit All when you manually stage your changes.
From the Git menu on the menu bar, choose New Branch... to open the Create a new branch window.
In the Create a new branch window, enter a descriptive branch name to let others know what work the branch contains. By default, Visual Studio creates your new branch from the current branch. The Checkout branch checkbox automatically switches you to the newly created branch. Select Create.
Add a README.md file to your cloned repo. In Solution Explorer, you can browse the repo contents using Folder View or open Visual Studio solutions in the repo. Git tracks changes made both inside and outside of Visual Studio.
When you're satisfied with your changes, save them in Git using a commit. In the Git Changes window, enter a message that describes the changes, and then select Commit All. Commit All commits unstaged changes and skips the staging area. You can choose to stage all files before committing by selecting the stage all + (plus) button at the top of the Changes section in the Git Changes window.
Select the commit information link to get further details about the commit.
Piezīme
If you have multiple files and you don't want to commit them all, you can right-click each file and choose Stage. When you've staged all the files you'd like to commit, select Commit Staged. Commit Staged replaces Commit All when you manually stage your changes.
In Team Explorer, select the Home button and choose Branches.
Right-click the default branch, often named main, and then choose New Local Branch From...
Enter a descriptive branch name to let others know what work the branch contains. Select Create Branch.
Add an README.md file to your cloned repo. From the Home view of Team Explorer, you can browse the repo contents using Show Folder View or open Visual Studio solutions in the repo. Git tracks changes made both inside and outside of Visual Studio.
When you're satisfied with your changes, save them in Git using a commit. Open the Changes view of Team Explorer by selecting the Home button and choosing Changes.
Enter a message that describes the commit, and then select Commit All.
Piezīme
If you have multiple files and you don't want to commit them all, you can right-click each file and choose Stage. When you've staged all the files you'd like to commit, select Commit Staged. Commit Staged replaces Commit All when you manually stage your changes.
Create a branch where you make your changes to the code. If you're collaborating with someone using a branch they've created, you can skip to the following git checkout step.
Console
> git branch ReadMeFix
Choose a descriptive branch name for your work to remind you and others what kind of work is in the branch.
Check out your branch so you can start working in it.
Console
> git checkout ReadMeFix
You can also use the checkout command to start working on a branch that other team members are already working in.
Make changes by using your favorite tools on the code.
When you're satisfied with the changes, even if you aren't ready to share the work, save them in Git using a commit. Your changes won't be shared until you push them, as described in the following section.
Console
> git commit -a -m "Descriptive message"
This command saves your changes locally to a new commit in Git. Make sure to give the commit a short message that describes your changes after -m.
Share your changes
After you've added one or more commits to a branch and you're ready to share those changes with others, push your commits so others can see them.
Once you've pushed your commits, you can create a pull request. A pull request lets others know you'd like to have your changes reviewed. After approval, a pull request typically adds your changes to the default branch of the remote repository.
In the Git Changes window, select the up-arrow push button to push your commit.
Or, you can push your changes from the Git Repository window. To open the Git Repository window, select the outgoing / incoming link in the Git Changes window.
Or, you can push your changes from the Git menu on the menu bar.
Create a pull request so that others can review your changes. If you've just pushed your changes from the Git Changes window, you can select the Create a Pull Request link to open a web browser where you can create a new pull request in the Azure Repos web portal.
Or, if you've just pushed your changes from the Git Repository window, you can select the Create a Pull Request link at the top of that window.
Or, you can right-click any branch in the Git Repository window and select Create Pull Request.
When the pull request opens in the Azure Repos web portal, verify your source and destination branches. In this example, we want to merge commits from the add-readme-file branch into the main branch. Enter a title and optional description, specify any reviewers, optionally associate any work items, and then select Create.
For more information on pull requests, see the Pull request tutorial.
In the Git Changes window, select the up-arrow push button to push your commit.
Or, you can push your changes from the Git Repository window. To open the Git Repository window, select the outgoing / incoming link in the Git Changes window.
Or, you can push your changes from the Git menu on the menu bar.
Create a pull request so that others can review your changes. If you've just pushed your changes from the Git Changes window, you can select the Create a Pull Request link to open a web browser where you can create a new pull request in the Azure Repos web portal.
Or, if you've just pushed your changes from the Git Repository window, you can select the Create a Pull Request link at the top of that window.
Or, you can right-click any branch in the Git Repository window and select Create Pull Request.
When the pull request opens in the Azure Repos web portal, verify your source and destination branches. In this example, we want to merge commits from the add-readme-file branch into the main branch. Enter a title and optional description, specify any reviewers, optionally associate any work items, and then select Create.
For more information on pull requests, see the Pull request tutorial.
In Team Explorer, select Home and then choose Sync to open Synchronization.
You can also go to the Synchronization view from Changes by choosing Sync immediately after making a commit.
In the Synchronization view, choose Push to upload your commit to the remote repo. If this is your first push to the repo, you'll see the message: The current branch does not track a remote branch..., which lets you know that your commit was pushed to a new branch on the remote repo and that future commits pushed from the current branch will be uploaded to that remote branch.
Create a pull request so that others can review your changes. Open Pull Requests in Team Explorer by selecting Home and choosing Pull Requests.
In Pull Requests, you can view pull requests opened by you, assigned to you, and you can create new pull requests. Select New Pull Request to open a web browser where you can create a new pull request in the Azure Repos web portal.
When the pull request opens in the Azure Repos web portal, verify your source and destination branches. In this example, we want to merge commits from the add-readme-file branch into the main branch. Enter a title and optional description, specify any reviewers, optionally associate any work items, and then select Create.
For more information on pull requests, see the Pull request tutorial.
Push your branch so that others can see the changes you've saved.
Console
> git push -u origin ReadMeFix
Open the project in the web portal and browse to your repository under the Code tab. Select Create a pull request to create a pull request for the branch that you pushed.
Verify your branches. In this example, we want to merge the commits from the ReadMeFix branch into the main branch. Enter a title and optional description, specify any reviewers, optionally associate any work items, and select Create.
Once the changes are approved, complete the pull request.
A complete pull request adds your changes from the branch into the main branch of the code.
For more information on pull requests, see the pull request tutorial.
Sync with others
You can keep your local branches in sync with their remote counterparts by pulling commits created by others. Although Git is good at merging incoming changes with your changes, sometimes you might have to resolve a merge conflict. While you're working on your feature branch, it's a good idea to periodically switch to your main branch and pull new commits to keep it current with the remote main branch.
In the Git Changes window, you can keep your local branch current with its remote counterpart by using the Fetch, Pull, Push, and Sync buttons.
From left to right in the previous screenshot, the button controls are:
Fetch downloads remote commits that aren't in your local branch, but doesn't merge them.
Pull performs a fetch and then merges the downloaded commits into your local branch.
Push uploads your unpushed commits to the remote repository, which adds them to the corresponding remote branch.
Sync performs a Pull then a Push.
You can also select Fetch, Pull, Push, and Sync from the Git menu.
In the Git Changes window, you can keep your local branch current with its remote counterpart by using the Fetch, Pull, Push, and Sync buttons.
From left to right in the previous screenshot, the button controls are:
Fetch downloads remote commits that aren't in your local branch, but doesn't merge them.
Pull performs a fetch and then merges the downloaded commits into your local branch.
Push uploads your unpushed commits to the remote repository, which adds them to the corresponding remote branch.
Sync performs a Pull then a Push.
You can also select Fetch, Pull, Push, and Sync from the Git menu.
In Team Explorer, select Home and choose Sync to open Synchronization.
You can download the latest changes to your branch using the Pull link. There are two Pull links, one near the top and one in the Incoming Commits section. You can use either because they both do the same thing.
Switch to the branch where you want to download the changes others have made.
Console
> git checkout ReadMeFix
In this example, you pull changes made by others on your team to the ReadMeFix branch to your local copy of the branch.
Pull the changes made by others to your local branch.
Console
> git pull
Git downloads the changes and merges them with your own changes into your local branch.
Pievienojieties meetup sērijai, lai kopā ar citiem izstrādātājiem un ekspertiem izveidotu mērogojamus AI risinājumus, kuru pamatā ir reālas lietošanas gadījumi.