Skip to content

Instantly share code, notes, and snippets.

@mfurlend
Last active November 20, 2015 20:40
Show Gist options
  • Save mfurlend/972809122dc92d17bc8f to your computer and use it in GitHub Desktop.
Save mfurlend/972809122dc92d17bc8f to your computer and use it in GitHub Desktop.
Create a git branch from (un?)committed changes

If you hadn't made any commit yet, only (1: branch) and (3: checkout) would be enough.
Or, in one command: git checkout -b newBranch.

As mentioned in the git reset man page:

1. $ git branch topic/wip    
2. $ git reset --soft HEAD~3 
     (or --hard to remove unindexed files) 
2. $ git checkout topic/wip
  1. You have made some commits, but realize they were premature to be in the "master" branch. You want to continue polishing them in a topic branch, so create "topic/wip" branch off of the current HEAD.
  2. Rewind the master branch to get rid of those three commits.
  3. Switch to "topic/wip" branch and keep working.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment