Skip to content

Instantly share code, notes, and snippets.

@m6w6
Last active October 26, 2020 21:23
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save m6w6/0267258551a7236b52061df01b95b676 to your computer and use it in GitHub Desktop.
Save m6w6/0267258551a7236b52061df01b95b676 to your computer and use it in GitHub Desktop.
git: move some recent commits from master to a new branch

Sometimes, I find myself in a series of commits which should have been done in a separate branch:

A - B - C - D - E - F (master)
            ^- first commit that should not be in master

Here's what it should look like:

A - B - C (master)
         \
          D - E - F (branch)

And here's what to be done:

(master)$ git checkout -b branch
(branch)$ git checkout master
(master)$ git reset --hard C

First, create the branch off the last commit, then go back to master and reset it to ref C. Done.

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