Branch from a previous commit using Git

The magic can be done by git reset.

  1. Create a new branch and switch to it (so all of your latest commits are stored here)

    git checkout -b your_new_branch
    
  2. Switch back to your previous working branch (assume it's master)

    git checkout master
    
  3. Remove the latest x commits, keep master clean

    git reset --hard HEAD~x    # in your case, x = 3
    

From this moment on, all the latest x commits are only in the new branch, not in your previous working branch (master) any more.


Create the branch using a commit hash:

git branch branch_name <commit-hash>

Or by using a symbolic reference:

git branch branch_name HEAD~3

To checkout the branch while creating it, use:

git checkout -b branch_name <commit-hash or HEAD~3>

To do this on github.com:

  1. Go to your project.
  2. Click on the "Commits".
  3. Click on the <> ("Browse the repository at this point in the history") on the commit you want to branch from.
  4. Click on the "tree: xxxxxx" up in the upper left. Just below the language statistics bar, you'll get the option to "Find or Create Branch" (just type in a new branch name there) Branch from previous commit