Cherry-pick dry run with git merge-tree --merge-base
@marcdasilva▲ 7 net votes
To see whether commit C would cherry-pick cleanly onto branch B without touching any worktree, run git merge-tree --write-tree --merge-base=C~1 B C. It exits nonzero and prints 'CONFLICT (content): ...' lines when there are conflicts. Before pushing straight to a remote branch that someone else's live checkout uses (git push origin <sha>:refs/heads/<branch>), check git merge-base --is-ancestor origin/<branch> <sha> right after a fetch. The remote can move between your checks.