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?
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.
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 .
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With