Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git rebase in Visual Studio

I suppose I'm getting confused about the wording within the Visual Studio 2019 Git Rebase UI. Silly question.

Scenario: I'm working in a branch called COREv2.0 . Bug fixes and other such things have been committed to master. COREv2.0 is still a work in progress, but I want to pull in those changes from master so I have those fixes that master has.

Thus, in my own words, I believe I want to rebase the COREv2.0 branch on the current master.

In Visual Studio, do I need to rebase FROM the current branch (COREv2.0) ONTO master? Or do I have that reversed? Does this screenshot represent what I'm wanting to do here?

enter image description here

like image 920
Jason Eades Avatar asked Mar 08 '21 22:03

Jason Eades


People also ask

How do I rebase code in Visual Studio?

Once you have your commits ready, we can click the Start Rebase button. You will then be presented with a screen in VS Code to reword your commit message. Write your new message, and save and close the file to continue. After this, our rebase is complete.

What is git rebase use for?

Rebase is one of two Git utilities designed to integrate changes from one branch onto another. Rebasing is the process of combining or moving a sequence of commits on top of a new base commit. Git rebase is the linear process of merging.


2 Answers

In Visual Studio, do I need to rebase FROM the current branch (COREv2.0) ONTO master?

Yes.

One of the first rule of Git is that you can only change the branch you have checked out i.e. the "current branch".

(Side note: The reason is because a lot of git actions could end up with conflicts to solve by the user and in this case, you need to have a working directory to work into.)

The 'onto' branch is the one with which you want to sync with. With a feature branch, it's most of the time master that you want to rebase onto.. .

Does this screenshot represent what I'm wanting to do here?

Yes.

A picture could help understand : https://cms-assets.tutsplus.com/uploads/users/585/posts/23191/image/rebase.png

like image 172
Philippe Avatar answered Oct 17 '22 21:10

Philippe


Does this screenshot represent what I'm wanting to do here?

It's a little different in Visual Studio 2019. Here you can rebase branches in "Branches" pane of "Git Repository" tab, which is accessible from both View>Git Repository or Git>Manage Branches menus.

To rebase your feature branch onto master:

  1. checkout feature branch
  2. in the list of branches in "Branches" pane, right-click on master
  3. find and click the Rebase '<feature-branch>' onto 'master' item in popup

This is equivalent to:

git rebase master <feature-branch>

or

git rebase master

, when the feature branch is checked out.

like image 41
saastn Avatar answered Oct 17 '22 22:10

saastn