Move Last Git Commit to New or Existing Branch
Sometimes you may begin work on a specific branch (say ‘master’) and realise that it would be better off to move these commits into a separate branch. This can be simply achieved using Git, either to a brand new branch or an existing branch.
The simpler of the two methods is to create a new branch who’s HEAD is that of the existing branches last commit. Using the following commands will create a new branch called ‘feature’ and then hard resets (staging and working tree) the existing branches HEAD to the previous commit.
If on the other hand you wish to move these commits into an existing branch you must first merge the new commits in and then follow the steps above.