title | titleSuffix | description | ms.assetid | ms.technology | toc | ms.topic | ms.date | monikerRange |
---|---|---|---|---|---|---|---|---|
Share your code with Git using Visual Studio 2015 |
Azure Repos |
Share code in Git using Visual Studio |
0c1dc48e-6f52-499d-a03e-6361c9a838dd |
devops-code-git |
show |
quickstart |
08/29/2017 |
>= tfs-2015 |
Azure Repos | Azure DevOps Server 2020 | Azure DevOps Server 2019 | TFS 2018 | TFS 2017 | TFS 2015
[!div class="op_single_selector"]
This article walks you through the steps to get a Visual Studio solution on your PC into an Azure DevOps Git repo you can share with others. If you want to work with a Visual Studio solution hosted in an existing repo, see the Git tutorial.
Create a new local Git repo for your project by selecting on the status bar in the lower right hand corner of Visual Studio.
This will create a new repo in the folder the solution is in and commit your code into that repo.
Once you have a local repo, select items in the status bar to quickly navigate between Git tasks in Team Explorer.
shows the number of unpublished commits in your local branch. Selecting this will open the Sync view in Team Explorer.
shows the number of uncommitted file changes. Selecting this will open the Changes view in Team Explorer.
shows the current Git repo. Selecting this will open the Connect view in Team Explorer.
shows your current Git branch. Selecting this displays a branch picker to quickly switch between Git branches or create new branches.
-
In the Sync view in Team Explorer, select the Publish Git Repo button under Publish to Azure Repos.
-
Verify your email and select your account in the Account Url drop down.
-
Enter your repository name and select Publish Repository.
This creates a new Project in your account with the same name as the repository. To create the repo in an existing Project, click Advanced next to Repository name and select a project.
Your code is now in a Git repo in Azure Repos. You can view your code on the web by selecting See it on the web .
-
As you write your code, your changes are automatically tracked by Visual Studio. You can commit changes to your local Git repository by selecting the pending changes icon (
) from the status bar.
-
On the Changes view in Team Explorer, add a message describing your update and commit your changes.
-
Select the unpublished changes status bar icon (
) or the Sync view in Team Explorer. Select Push to update your code in Azure DevOps Services/TFS.
Sync your local repo with changes from your team as they make updates.
-
From the Sync view in Team Explorer, fetch the commits that your team has made. Double-click a commit to view its file changes.
-
Select Sync to merge the fetched commits into your local repo and then push any unpublished changes to Azure Repos.
-
The changes from your team are now in your local repo and visible in Visual Studio.
Set up a build for your code and learn more about using Git in the Azure Repos Git tutorial.
A: The Publish link in the status bar ( ) was added in Visual Studio 2015 Update 2 and will only appear when you have Git as your source control provider. If your code is
already in a Git repo, you won't see the Publish button in the status bar, but the information from your local repo instead.
If you are in a previous version of Visual Studio, create a local Git repo for your project by selecting the Create new Git repository option in the New Project window when you create a new project.
You can create a local Git repo for an existing solution by right-clicking your project in the Solution Explorer and selecting Add Solution to Source Control.
A: To see what's changed in a commit, go to the Synchronization page in Team Explorer and right-click on the commit. Select View Commit Details. You can then right-click on any file modified by the commit and select Compare with Previous... to view the changes compared to the previous version of the file.
A: You can include work items in your commits through Related Work Items in the Changes page in Team Explorer.
Work items can be included in commits by adding #ID into the commit message. For example, "Fixing bug #23 in the reporting tools" would link work item 23 to the commit. The work item is linked when the commit is pushed to Azure Repos.
A: Visual Studio's Team Explorer and the Git command line work great together. Changes to your repos made in either tool will be reflected in the other. Make sure to install the latest release of Git for Windows, which has tools to help you connect to your Azure DevOps Services/TFS repos.
See the Azure Repos Git tutorial and the command reference for additional help using Git from the command line.