Move last commit to a feature branch
Public
28 Sep 14:21

When you accidentally commit to master/staging and need to move the commit to a feature branch:

git branch new-branch-name # create a new branch from current one
git reset --hard HEAD~1 # remove last commit (change the number to remove more)
git checkout new-branch-name # checkout the new branch

Comments

Joe
mus
edit - added a new tag :)
Joe
mus
Warning - only do this with local commits, not with commits you've already pushed.
Joe
aleksander
Looks scary but it's very useful. Thanks @mus