I have started using git rebase
recently and am not 100% certain I'm doing it right. For the sake of the question, there are two branches in origin, master
and next
, which was branched from master
.
Since last sync between the two, master
had 2 commits and next
6:
$ git log --oneline origin/next..origin/master
59b5552 master commit #2
485a811 master commit #1
$ git log --oneline origin/master..origin/next
4ebf401 next commit #6
e9b6586 next commit #5
197ada0 next commit #4
4a2c3c6 next commit #3
040a055 next commit #2
84537bf next commit #1
When I checkout next
and execute git rebase -i origin/master
, I get the following:
$ git status
# On branch next
# Your branch and 'origin/next' have diverged,
# and have 8 and 6 different commits each, respectively.
And finally after doing git pull --rebase
, the two commits from master
are in next
:
$ git log --oneline origin/next..next
8741d09 master commit #2
485a811 master commit #1
Questions:
- Is this correct approach?
- Why are there
8 and 6
different commits untilpull --rebase
is run? - Is it possible to simplify the flow?
Much obliged :)
git rebase --pull
is much likegit pull --rebase
. It does a fetch and then agit rebase @{u}
Well, that's a lie, but it is an easy way to think about it. But the point is that your local branch is reset to @{u} and then all local commits on your old branch before the reset are replayed on top of what upstream has. This allows a trivial fastforward push upstream. – Tuition