Working on feature branch and doing some non-feature-related work in commit D
. Now I want to move (not just cherrypick) that commit to another refactor branch.
C - D (HEAD w. uncommitted changes) [feature branch]
/
A-B [main branch]
\
D [refactor branch]
Currently I know of two ways of doing this:
Option 1 with interactive rebasing
git checkout -b refactor
(and perhaps stash or WIP the uncommitted changes)git rebase -i main
and delete all the feature related commitsgit switch feature
Option 2 with cherry-picking
git switch main
(perhaps stash or WIP the uncommitted changes before)git checkout -b refactor
git cherry-pick <D hash>
git switch feature
git rebase refactor
Are there any other good ways for doing it?
It would be handy if there was a to commit to another branch than the current checkout (HEAD).
Or if there would a way to have the cherry-pick also remove the commit from the feature branch.
(I'm wondering if git-filter-repo could be used to automate step 2 (git rebase -i main
and delete all the feature related commits) in option 1 by saying that it should remove all similar commits that can be found on the refactor branch.)