Sim Sca
Sim Sca

Reputation: 433

Correct Github Rebase work

I have no experience on Github, so I hope someone can help me to figure out the correct command sequence.

I'm on a Github repo that presents this situation:

------master     
     /
-- dev
     \
      --------extrabranch c11 --- extrabranch c12

That is, starting from the last commit on dev, I've merged it on master, then created a new branch extrabranch and added two commits to that branch. This situation is the same in the Github remote repository, and in local.

Now I would rebase extrabranch on dev.

Trying locally:

git rebase dev extrabranch
Current branch extrabranch is up to date.
git pull --rebase
Current branch extrabranch is up to date.

But the commits graph remains the same as the above. Can someone explain to me why branch dev doesn't contain the commits c11 and c12 of rebased extrabranch?

Edit: my goal is to merge extrabranch into dev, and delete extrabranch, as cleanly as possible.

Upvotes: 0

Views: 68

Answers (1)

Dan Lowe
Dan Lowe

Reputation: 56568

Let's look at your graph. I have modified it to show a commit c10, which is where master and dev point. Your illustration doesn't show this, but by definition there must be a commit there.

-- c10 [master, dev]
     \
      --- c11 --- c12 [extrabranch]

The purpose of git rebase is to move commits, to be based on a specific point in the graph. You are telling git to rebase extrabranch (c11 + c12) onto dev (c10). However, extrabranch is already based on dev, so there is nothing to do.

You say your goal is to merge extrabranch into dev, then delete extrabranch as cleanly as possible. The simplest approach is to merge it. Because there are no conflicts in the way, it will merge using fast-forward.

git checkout dev
git merge extrabranch

That will move the dev branch to where c12 sits.

-- c10 [master]
     \
      --- c11 --- c12 [extrabranch, dev]

After that you should be able to delete extrabranch if you want to.

git branch -d extrabranch
-- c10 [master]
     \
      --- c11 --- c12 [dev]

This is assuming that there are no upstream commits on dev, which your post does not show. You can use pull or fetch to figure that out, though.

Upvotes: 3

Related Questions