Skip to content

Instantly share code, notes, and snippets.

@iolloyd
Created December 9, 2016 10:37
Show Gist options
  • Save iolloyd/4018744c054b223c035ed8233f1ea6ce to your computer and use it in GitHub Desktop.
Save iolloyd/4018744c054b223c035ed8233f1ea6ce to your computer and use it in GitHub Desktop.
Branching from the wrong branch in git
# branch/current <- Branch with commits
# branch/main <- Branch that should have been branched from
# branch/other <- Branch that was actually branched from
git checkout branch/main
git checkout -b branch/correct
git rebase --onto branch/correct branch/other branch/current
@iolloyd
Copy link
Author

iolloyd commented Dec 9, 2016

First, checkout the branch that you wanted to branch from originally.

Make a new branch, here we've called it branch/correct.

Rebase the changes made that are the difference between the branch you branched from and the branch you made with your latest commits.

Done.

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