Continuing our previous posts, let us now see how we can work with branches within Visual Studio 2019.
Branches give the option to isolate the work from the original code base, this way we could have a developer(s) working on bug fixes, new features etc. which then can be merged back to the master branch later.
Open the Branches page in Team Explorer and click on the New Branch option.
Here we have created a new branch name MyFirstBranch from the master branch, and have also selected the option Checkout branch to work with that branch.
Create Branch creates the new branch as shown below.
To navigate to the branches page of Team Explorer, we can also use the Status bar of Visual Studio
Now let us make some changes in the program.cs file in the new branch created.
Do Commit and Push
From the team explorer, Branches page, we can see that the new branch has been added in the remote repository after commit.
To merge changes back from this new branch to the master branch, click on the master branch and select Merge option in the Branches page
- Merge from Branch: MyFirstBranch
- Into current branch: master.
As we have selected the option Commit changes after merging click on Merge pushes and sync the changes in the master branch in the remote repository as shown below.
We also have the options of deleting the branches as shown below, if they are not required anymore.
In this post, we saw how to work with Branches and how to merge it back to the base code.
Hope it helps..
4 thoughts on “How to – Work with Git Branches in Visual Studio 2019”
To be more realistic, the branch should be created in GitHub (outside VS) before creating a branch in VS , because if we create a branch in VS and wait to do some changes then Commit and push, so the branch will be reflected in GitHub, We have to understand that other developer may want to create a branch as well and at the time he does, he/she will find already a Branch created since normally we create branches naming them using a project id or case number. In other words if developers create local branches in VS without reflecting the newly created branch promptly in GitHub it may cause problems.
LikeLiked by 1 person
Thanks Gregory for sharing your knowledge. Much appreciated.