Move Recent Commits to a New Feature Branch

by Kirk Madera

Engineers reusable modular solutions to maintain environments and deployment strategies across teams. Works for food.

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

  1. // Stash your current edits if you have uncommitted work
  2. git stash;
  3.  
  4. // Make a new branch from the latest commit on development
  5. git branch new_feature;
  6.  
  7. // Find the commit id just before your first commit to
  8. // development branch
  9. git log;

It will look something like this:

  1. commit a0b446145776970738952a4687a2c91cecd12b5a
  2. Author: My Name <my.name@amplificommerce.com>
  3. Date:   Fri Oct 2108:47:582011-0700
  4.  
  5. Commit message 1
  6.  
  7. commit d0b84614377c900758952ac687acc91cecd12b5d
  8. Author: Kirk Madera <kirk.madera@amplificommerce.com>
  9. Date:   Fri Oct 2108:47:582011-0700
  10.  
  11. Commit message 2

Pick the first commit this is before your commits.

  1. // Reset the development branch to this commit. Make sure
  2. // you use the correct commit id;
  3. git reset--hard d0b84614377c900758952ac687acc91cecd12b5d;
  4.  
  5. // Checkout your new branch
  6. git checkout new_feature;
  7.  
  8. // Apply your stash. This will add your uncommitted edits
  9. // back in
  10. git stash apply stash@{0};
  11.  
  12. // Clear your stash
  13. git stash clear;
  14.  
  15. // Push your branch to the main repo to allow for
  16. // collaboration & testing
  17. git push origin new_feature;
Tags

Move Recent Commits to a New Feature Branch

Move Recent Commits to a New Feature Branch

by Kirk Madera

Engineers reusable modular solutions to maintain environments and deployment strategies across teams. Works for food.

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

  1. // Stash your current edits if you have uncommitted work
  2. git stash;
  3.  
  4. // Make a new branch from the latest commit on development
  5. git branch new_feature;
  6.  
  7. // Find the commit id just before your first commit to
  8. // development branch
  9. git log;

It will look something like this:

  1. commit a0b446145776970738952a4687a2c91cecd12b5a
  2. Author: My Name <my.name@amplificommerce.com>
  3. Date:   Fri Oct 2108:47:582011-0700
  4.  
  5. Commit message 1
  6.  
  7. commit d0b84614377c900758952ac687acc91cecd12b5d
  8. Author: Kirk Madera <kirk.madera@amplificommerce.com>
  9. Date:   Fri Oct 2108:47:582011-0700
  10.  
  11. Commit message 2

Pick the first commit this is before your commits.

  1. // Reset the development branch to this commit. Make sure
  2. // you use the correct commit id;
  3. git reset--hard d0b84614377c900758952ac687acc91cecd12b5d;
  4.  
  5. // Checkout your new branch
  6. git checkout new_feature;
  7.  
  8. // Apply your stash. This will add your uncommitted edits
  9. // back in
  10. git stash apply stash@{0};
  11.  
  12. // Clear your stash
  13. git stash clear;
  14.  
  15. // Push your branch to the main repo to allow for
  16. // collaboration & testing
  17. git push origin new_feature;
Tags