Move a commit to a different branch
Sometimes you might be working on a branch. Maybe it is a new feature or an experiment. But a change you make should apply across the board straight away. Not only when the feature is complete.
Firstly, commit the change to the branch you are working in.
Make a note of the commit hash -
checkout the branch you want to move it to. E.g.
git checkout main.
cherry-pick command to move the commit.
git cherry-pick <commit-hash>
At this point the commit is on the
You can correct the history on the WIP branch by running:
git checkout <wip-branch> git rebase main
This works for me but if anyone thinks this can or should be done differently, do let me know.