Skip to content

Instantly share code, notes, and snippets.

@hartfordfive
Created April 18, 2016 17:31
Show Gist options
  • Select an option

  • Save hartfordfive/8962c872d8235cec085b41bc5f5ec7ae to your computer and use it in GitHub Desktop.

Select an option

Save hartfordfive/8962c872d8235cec085b41bc5f5ec7ae to your computer and use it in GitHub Desktop.
Move accidental commit on "master" to another branch [Git]
In the situation you've accidentally already committed changes to your "master" branch and want the moved to a seperate branch:
git branch [NEW_BRANCH_NAME] # Create new branch with the changes you just committed
git reset --hard HEAD~[NUM_COMMITS] # Go back [NUM_COMMITS] commits. You *will* lose uncommitted work.*1
git checkout [NEW_BRANCH_NAME] # Checkout the newly created branch that contains your modifications
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment