Use Git in Visual Studio 2019

Bogdan Hatis
4 min readNov 21, 2020

After the migration from TFSVC to Git is done, now is time to learn how to use Git in Visual Studio 2019 using Git integrated options from VS.

First of all we need to map our repository (in this example I’ll use the DEV branch).

Open VS2019 -> Continue without code and navigate to Team explorer. Click on Manage connections option

On local Git Repositories press Clone option and enter the url of the Git repo to clone and click Clone

Double click on the new created repository and go to branches

Go to remotes/origin and map DEV repo (double click).

Now the repository is set to work on Dev branch.

If you are working into a team is better to use your local branch when you are working on your tasks, so you need to create a new branch from your TFS/Azure DevOps work tab.

Navigate to TFS -> Project -> Work section and open a Task

Create new branch with a task specific name, based on DEV brach

Create a new branch

Go back to visual studio and choose Sync section and press Sync option.

Now go to branches and choose to work on the new branch.

After you finish your task is time to commit changes (in my case the gitattributes and gitignore files). Go to changes section, add a specific message and click Commit All.

Now press sync to share your changes with the server and press Push

It’s time to create a pull request and after that to merge changes into default branch. After the push navigate to TFS -> Project -> Code section and press Create a pull request. Set to merge to DEV branch, set the Reviewers and press Create.

Wait until all reviewers approve your changes. Use comments and code review (Files section) for reviewing the code.

After the pull request is Approved by all reviewers, then you or the Git master could Complete the pull request, by pressing the Complete button. Now check the Delete your branch after merging and click Complete merge. If you want to keep history clean and to drop all references about task branch then check Squash changes after merging.

After merge in the commit section we’ll have the entire commits history

Fetch and pull changes

To keep your local repository updated you need to use fetch, to see the differences between local repository and origin repository for a specific branch.

To update local repository with these changes use Pull option.

Now local brach is updated to last commit.

Enjoy!

--

--

Bogdan Hatis

Experienced developer, product manager and CTO with a demonstrated history of working in the information technology, services and fintech industry.