Move Recent Commits to a New Feature Branch

So you’ve made a few commits to the development branch and now realize that you need to make a feature branch for this and revert your commits to development.

Here’s how:
* This assumes you are currently working within the development branch and may have uncommitted work

// Stash your current edits if you have uncommitted work
git stash; 

// Make a new branch from the latest commit on development
git branch new_feature; 

// Find the commit id just before your first commit to 
// development branch
git log; 

It will look something like this:

commit a0b446145776970738952a4687a2c91cecd12b5a
Author: My Name <>
Date:   Fri Oct 21 08:47:58 2011 -0700

Commit message 1

commit d0b84614377c900758952ac687acc91cecd12b5d
Author: Kirk Madera <>
Date:   Fri Oct 21 08:47:58 2011 -0700

Commit message 2

Pick the first commit this is before your commits.

// Reset the development branch to this commit. Make sure 
// you use the correct commit id;
git reset --hard d0b84614377c900758952ac687acc91cecd12b5d; 

// Checkout your new branch
git checkout new_feature; 

// Apply your stash. This will add your uncommitted edits 
// back in
git stash apply stash@{0}; 

// Clear your stash
git stash clear; 

// Push your branch to the main repo to allow for 
// collaboration & testing
git push origin new_feature;