Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to rebase from parent branch?

Below is the current scenario of branch X & Y in Git:

   A - B [origin/master]
     \
      C - D - G - H [origin/X]
           \
            E - F [Y]

where,

developer1 is working on branch X

and

am working on branch Y.

X is parent branch of Y.


Currently branch Y is pointing remotely to origin/Y

I want to include changes of origin/X in branch Y before working further on branch Y. So, I would like to see, something like:

A - B [origin/master]
     \
      C - D - G - H [origin/X]
                   \
                    E1 - F1 [Y]

1) What are the git commands for rebasing my branch Y?

2) What does this command(git branch -u origin/X Y) do?

like image 391
overexchange Avatar asked Jul 21 '19 02:07

overexchange


People also ask

What does it mean to rebase a branch?

From a content perspective, rebasing is changing the base of your branch from one commit to another making it appear as if you'd created your branch from a different commit. Internally, Git accomplishes this by creating new commits and applying them to the specified base.

Why you should rebase instead of merge?

But, instead of using a merge commit, rebasing re-writes the project history by creating brand new commits for each commit in the original branch. The major benefit of rebasing is that you get a much cleaner project history. First, it eliminates the unnecessary merge commits required by git merge .


1 Answers

It's simple:

git checkout Y
git rebase origin/X

That is, assuming you will do it after someone (the other developer) rebases X (I see it was rebased on top of master).

Second question: it creates a local branch Y that has "upstream" branch set to origin/X. Upstream is like the branch that Y will use as the base when you try commands like git pull or git pull -r.

like image 181
eftshift0 Avatar answered Oct 18 '22 03:10

eftshift0