If the work has already been merged into main
branch (or whatever the upstream is), then the easiest thing you can do is rewrite the work (which is a straight line, right?) so that git does not see it as merged anymore (well, because if you rewrite it, then it has not been merged before, right?).
So.... say the branch is feature
and the upstream is main
:
git checkout $( git merge-base feature commit-from-main-before-merge-of-feature )
# now we are at the commit where feature was started
git cherry-pick HEAD..feature
# now all commits that make up feature are on a new history
# that, to git, hasn't been merged
git branch -f feature # set feature branch over here
Now, if you try to merge feature
into master
, git won't complain.... well, it might complain because of the mess with the reversal but at least it won't tell you that what you want to merge is merged already. It will really try to merge.