Skip to content

Instantly share code, notes, and snippets.

@jasdeepkhalsa
Last active May 15, 2019 12:50
Show Gist options
  • Select an option

  • Save jasdeepkhalsa/5a992ff11fea913641a034e3a4c5890d to your computer and use it in GitHub Desktop.

Select an option

Save jasdeepkhalsa/5a992ff11fea913641a034e3a4c5890d to your computer and use it in GitHub Desktop.
Complex git rebase strategies (using --rebase-merges)

Firstly make sure you're using a decent editor with your git e.g. Atom, VS Code etc.

git config --global core.editor "atom"

To modify a merge commit history, like the merges done by popular online version control systems such as GitLab or Bitbucket:

¢ git rebase --rebase-merges -i HEAD~1

Replace the 1 in the example above with the number of merge commits you wish to rebase with. Remember, merge commits can have a number of commits grouped under them

Please note: The --rebase-merges flag is only available as of git version 2.18 and higher. Check your local git version using git —version and upgrade if necessary

For a complex rebase, like changing the merge history as above, first switch to your branch and then try:

Note: I assume you have already done a git pull --rebase and git pull origin local-branch on the branch you'd like to rebase off

$ git rebase local-branch

or

$ git rebase origin remote-branch

If this doesn't work, switch to your branch and then try:

$ git pull origin remote-branch --rebase
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment