- Make sure you are on the affected branch:
git checkout wrong-branch
- Soft-reset the HEAD to the previous commit. In the words of
git status
, this will leave all your changed files as “changes to be committed”:git reset --soft HEAD^
- Stash away the uncommited changes resulting from the previous step:
git stash
- Apply the stashed changes onto the right branch:
git checkout right-branch &&
git stash pop
- Fix any resulting merge conflicts, then run
git commit -a
- If necessary, push the modified (wrong) branch to the remote:
git checkout wrong-branch && git push origin --force