Use Git in Visual Studio 2019

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

Image for post

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

Image for post

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

Image for post

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

Image for post
Create a new branch

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

Image for post

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

Image for post

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.

Image for post

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

Image for post

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.

Image for post

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.

Image for post

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

Image for post

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.

Image for post

To update local repository with these changes use Pull option.

Image for post

Now local brach is updated to last commit.

Enjoy!

1 Comments

  1. Wilson November 24, 2020 at 6:51 pm

    Execellent! I was wonder which is the correct order to use Git from VS and I found this article! Thank you!