Moving Git Commits to Another Branch
So today I absent mindedly made a sequence of commits to the wrong branch. Normally I would just cherry pick but today I decided to use a slightly different method. This method works for me as I tend to merge branches rather than rebase.
The first step is to checkout the branch where I want the commits to be.
git checkout CorrectBranch
Next I merge into that branch from the one where the commits actually are.
git merge WrongBranch
Finally I reset the branch that I wrongly committed to, to the commit I want it to be at. In my case there were three commits.
git checkout WrongBranch
git reset --hard HEAD~3
NOTE that in my case I had no changed working files that would get destroyed by this, if I had such files I would use the following
git checkout WrongBranch
git reset --keep HEAD~3