In this blog post, I will briefly describe the concept of rebasing and go over how it is done in Visual Studio.
Merging vs. Rebasing
When you are merging branches, you simply merge the latest dev branch into your current feature branch as shown in the diagram below.
Unlike merging, rebasing “re”-bases the feature branch with the latest dev branch.
When you rebase, the latest changes in the current branch (‘f1’ & ‘f2’) are internally saved for a moment. The latest pull from the dev branch (‘d2’ commit) in the current branch is then re-based with a ‘d4’ commit and the internally saved commits (‘f1’ and ‘f2’) are added back.
Rebasing in Visual Studio
Let’s now look at how rebasing is done in Visual Studio.
Here is an overview of the process:
- Commit and sync the changes in the current branch.
- Rebase the current branch onto the ‘develop’ branch.
- Merge conflicts in the detached branch.
Let’s imagine you added the ‘f1’ and ‘f2’ features. Commit and sync the changes.
Go to the ‘Branches’ tab in the Team Explorer and rebase the current feature branch onto develop branch.
Notice how a branch ‘Detached at {id}’ is created upon rebasing. This is a detached branch created internally for us to resolve conflicts.
Accept merge and resolve any conflict that is generated.
Return to the ‘Changes’ tab in the Team Explorer and click ‘Continue’ under ‘Rebase In Progress’.
You will then notice you are back in the feature branch.
You can now push the changes to your repository!