Visual Studio doesn’t support the git rebase workflow by default. I’ll show you the required settings that need to be changed.
The git rebase strategy is commonly used in larger software development projects. One main advantage to the git merge strategy is that if you work with feature branches, all commits of one feature are in line. When traversing the history you will always be in the same feature until back to the beginning. When using the git merge approach, commits of different features can be within your feature which makes it harder to debug in case of errors.
You want your history to look like this (features aren’t divided):
But it should not look like this (features are divided):
A good summary of the approaches (and the git terms in general) can be found in the following article:
When pulling via Visual Studio from a git repository, it will automatically use the git merge pattern by default. We have to change a setting to fix this. If you do a git rebase with a shell and try to push from Visual Studio, the following dialog appears.
When you click on Pull then Push or Pull, a git merge will be performed.
Another problem with Visual Studio is that it doesn’t allow you to push the changes after a git rebase. The commit history is reordered and that requires a push with the argument
--force-with-lease which Visual Studio doesn’t allow out of the box. A git merge doesn’t reorder the commit history, so a normal push is sufficient.
Source Control →
Git Global Settings, set
Rebase local branch when pulling to
True, and enable the checkbox
Enable push --force-with-lease.
On your next failed push after a git rebase, you will be presented a new option Force Push. This is what we want to rewrite the commit history in our favor.
The configuration is completed and should work fine ?
In this article, I showed you how to configure Visual Studio to support git rebase properly. If you keep running into problems, I suggest switching to a command line and executing the git commands from there. The git support of Visual Studio is getting better but is far from being perfect.