Skip to content

Instantly share code, notes, and snippets.

@flaf
Last active April 4, 2019 09:48
Show Gist options
  • Save flaf/5413059126ff5c15f0a86cad60bbcce4 to your computer and use it in GitHub Desktop.
Save flaf/5413059126ff5c15f0a86cad60bbcce4 to your computer and use it in GitHub Desktop.
Rebase an old branch

I have this:

A - B - C - F - G (master)
         \
          D - E (BranchB, origin/BranchB)

I want to have this:

A - B - C - F - G (master)
                 \   
                  D' - E' (BranchB, origin/BranchB)

Is it possible and how?

I thought that process could work:

git checkout BranchB
git rebase master BranchB

# I solve conflicts and "git add ...".
# Then, to finish the rebase:
git rebase --continue

git pull --rebase
git push

But I have this:

A - B - C - F - G (master)
         \
          D - E - F' - G' (BranchB, origin/BranchB)

Which is not exactly the result I want.

NB:

  • To see graphs in CLI:
git log --oneline --graph --decorate --all
git log --pretty=oneline --graph --decorate --all
  • Interesting link here.
@flaf
Copy link
Author

flaf commented Mar 28, 2019

Answer of rafasc on Freenode/#git (thx to him):

git checkout BranchB
git rebase master BranchB

# I solve conflicts with "vim ..." and "git add ...".
# Then, to finish the rebase:
git rebase --continue

# "git pull --rebase" is exactly what I don't want.
git push origin --force-with-lease

Interesting link about pull = fetch+merge

Sometimes after a git rebase --continue, I have this kind of error:

$ git rebase --continue
Applying: Define a setting for my vbox environment
No changes - did you forget to use 'git add'?
If there is nothing left to stage, chances are that something else
already introduced the same changes; you might want to skip this patch.

Resolve all conflicts manually, mark them as resolved with
"git add/rm <conflicted_files>", then run "git rebase --continue".
You can instead skip this commit: run "git rebase --skip".
To abort and get back to the state before "git rebase", run "git rebase --abort".

You have to resolve another conflicts (vim ... && git add ...) and launch:

git rebase --skip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment