Skip to content

Instantly share code, notes, and snippets.

@pcrockett-pathway
Created March 20, 2020 14:50
Show Gist options
  • Select an option

  • Save pcrockett-pathway/53fd8021412baac88f7e349d8f446273 to your computer and use it in GitHub Desktop.

Select an option

Save pcrockett-pathway/53fd8021412baac88f7e349d8f446273 to your computer and use it in GitHub Desktop.
Personal rebase summary

To move a range of commits in Git so they are based on a different commit:

git rebase --onto new-base current-base latest-commit
  • new-base: This is the commit you want to move the range to. This commit will be the new parent of the commits you're moving.
  • current-base: This is the commit that your range is currently based on. It is not the first commit in the range, but the parent of the first commit.
  • latest-commit: This is the tip, the most recent commit in your commit range.

From git rebase docs:

Here is how you would transplant a topic branch based on one branch to another, to pretend that you forked the topic branch from the latter branch, using rebase --onto.

First let’s assume your topic is based on branch next. For example, a feature developed in topic depends on some functionality which is found in next.

o---o---o---o---o  master
     \
      o---o---o---o---o  next
                       \
                        o---o---o  topic

We want to make topic forked from branch master; for example, because the functionality on which topic depends was merged into the more stable master branch. We want our tree to look like this:

o---o---o---o---o  master
    |            \
    |             o'--o'--o'  topic
     \
      o---o---o---o---o  next

We can get this using the following command:

git rebase --onto master next topic
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment