How To Configure Git Version Control In Visual Studio Team Explorer Step By Step

Introduction

How do we configure Git Version Control in Visual Studio Team Explorer? In this article, we will understand how to commit code in the remote repository.

Step 1

Open Visual Studio and go to menu Team =>Manage Connections, and click on manage connections then you will find Team Explorer at the right panel as shown  in the below screen.

Visual Studio

Step 2

You can see in Team Explorer there are two Visual Studio Version Control providers, one is Visual Studio Team Services; i.e., TFS, and  the second is Git. But none of them are connected in the Team Explorer. It is showing offline. Now create a local Git Repository. Once you click on “New” label you would get one input field, so enter your local repository path, for example (“E:\GITRepo”), and click on the “Create” button as in the below screen.

Visual Studio

Step 3

Once you click on the “Create” button then you will see created local Git repository (“GITRepo”):

Visual Studio

Step 4

Now double click on the created local Git repository “GITRepo”:

Visual Studio

Step 5

Now you can see local Git repository (“GITRepo”) has been connected from arrow 1 & 4, and by default master branch is selected from arrow 3 and two files have been added (staged changes) by Git utility from arrows 2 & 5. You can see “Commit Staged” button is disabled if you enter commit message then this button will be enabled, and you can commit your changes in the local Git repository as in the below screen.

Visual Studio

Once I entered commit message “Commit Staged” button has been enabled with options “Commit Staged”, “Commit Staged and Push” and “Commit staged and Sync”.

  1. "Commit Staged” will commit changes in local Git repository.
  2. “Commit Staged and Push” will commit in local as well as remote Git repository.
  3. "Commit staged and Sync” will commit in local as well as remote Git repository and update local Git repository from remote Git Repository i.e. pull all pending incoming changes from the remote.

The first option, “Commit Staged,” will work at this stage but the other  two options will not work because we have not configured remote Git repository yet.

Once you click “Commit Staged” you will get commit id from arrow 1 as in the below screen. You can see it is saying commit 355a5091 created locally. Sync to share your changes with the server.

Visual Studio

Step 6

Once you click on “Sync” link to share your changes with the server.

Visual Studio

Step 7

To share your changes with the server, click on Publish Git Repo. 

Visual Studio

If you see the above screen it is clearly mentioned that there is no remote configured for this local repository. Establish the remote by publishing to the URL of an existing empty repository.

Step 8

So now you must have Git remote repository. To get Git remote repository you must have a Git account for either personal or commercial use. To create Git account, you can simply go to Git official website: https://github.com/

If you have any existing Git account, you can login, otherwise you can create a new Git account.

I have an existing Git account and I have already logged-in and I am on my Git dashboard.

Visual Studio

To create a new Git remote repository, click on “New repository” button and once you click on this button you will find a new screen for creating a Git new remote repository. Let’s create “HelloWorldRepository” for demonstration purpose only.

Visual Studio

Once you click on “Create repository” button in the above screen you will see a repository created.

Visual Studio

Now we have created a Git remote repository “HelloWorldRepository” and the remote path is as below,

Visual Studio

Step 9

Let’s go back to Step 6 and try to connect this newly created Git remote repository in Visual Studio.

Visual Studio

Step 10

Once you click on “Publish” button you will as below screen.

Visual Studio

Step 11

Now you can see from the above screen our local branch is being pushed on the Git remote repository “HelloWorldRepository” 

Visual Studio

Now click on “Branches” in the above screen. You will see your Git local “GITRepo” repository master branch has been pushed to Git remote “HelloWorldRepository” repository master branch. You can see it in Visual Studio Team Explorer as well as your personal Git account “HelloWorldRepository” repository.

Git local (“GITRepo”) & remote (“HelloWorldRepository”) repository in Visual Studio Team Explorer.

Visual Studio

Git remote (“HelloWorldRepository”) repository in Git personal account.

Visual Studio

Local “GITRepo”,

Visual Studio

Step 12

Now let’s create a Demo Window Application in Visual Studio and try to commit all the changes in the remote repository. While creating new project make sure “Create new Git repository must be checked.” 

Visual Studio

Step 13

Once project is created go to Visual Studio Team Explorer home screen and click on “Changes” as below screen.

Visual Studio

Step 14

Once you click on “Changes” you will get all the newly added files in your local Git repository “GITRepo” 

Visual Studio

Step 15

You can see “Commit All” button is disabled once you enter commit message in commit message box this button will be enabled.

Visual Studio
  1. “Commit All” will commit changes in local Git repository.
  2. “Commit All and Push” will commit in local as well as remote Git repository.
  3. “Commit All and Sync” will commit in local as well as remote Git repository and update local Git repository from remote Git Repository i.e. pull all pending incoming changes from the remote.

Now let’s click on “Commit All” button and you can see all changes have been committed to your local repository as below screen,

Visual Studio

Step 16

Go to Step 13; i.e., Team Explorer home screen and click on “Sync” as below screen.

Visual Studio

Once you click on “Sync” button you will see the below screen.

Visual Studio
  1. From “Fetch” you can get all incoming changes.
  2. From “Pull” you can download remote changes.
  3. From “Push” you can share your local changes to the server.

Let’s click on Push. [Sync=Fetch+Pull+Push].

Visual Studio

From the above screen, you can see changes are being pushed to the server and you can see progress. Now you will see successfully pushed to origin/master.

Visual Studio

Now let’s verify all pushed changes are in the remote repository HelloWorldRepository.

Visual Studio

Now it has been verified that all changes have been pushed to the server; i.e., remote repository.

Congratulations,  you have successfully configured Git Version Control in Visual Studio Team Explorer. If you have any query or concern just do let me know or just put it in the comment box and I will respond as soon as possible. I am open to discussing anything even silly questions as well. If you have any suggestions related to this article, please let me know.

Summary

In this article, we have learned How to configure Git Version Control in Visual Studio Team Explorer.


Similar Articles