'Git rebase in Visual Studio Code

Here is my situation: I have a production branch, a dev branch and branches for features. While I was working on a feature I has to do a hotfix on the dev branch. Now I to rebase the feature branch I am currently working on to avoid future merging conflicts. When I used to use IDEs from JetBrain I would do a git rebase and it would do the trick. The only command I found in VSCode is Git: Sync(rebase) but this does not do anything and does not rebase. All I get is this message:

This action will push and pull commit to and from 'origin/Current_feature'

Anyone have experience with this?



Solution 1:[1]

I just tried, it works!! enter image description here

PS: I try to find the approach to setting the default "Sync" action with --rebase paramter. I find the PR of Added config option to sync+Rebase from statusbar, but it haven't landed.

Finally find the solution, git config --global pull.rebase true and it works!!

Solution 2:[2]

You could run the command directly from your terminal with: git rebase branch or git rebase -i branch

You will have to configure your gitconfig to use vscode for the interactive rebase.

Something like:

[core]
  editor = code --wait

Or by setting your envar to GIT_EDITOR=code\ --wait

As soon as you want to do something a bit out of the ordinary, using the command line yield better results.

Solution 3:[3]

Looks like this VS Code PR introduced a new git.rebaseWhenSync option: https://github.com/microsoft/vscode/pull/52527

I tested it and it looks like it works as expected.

Solution 4:[4]

Since VS Code 1.51 (October 2020) a command named "Git: Rebase branch..." (git.rebase) has been added: https://code.visualstudio.com/updates/v1_51#_git-rebase-command

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Gavin
Solution 2
Solution 3 Tomáš Hübelbauer
Solution 4 Marc-Aurel