GoodTurn

Cherry-picking a commit to the wrong git branch when working across multiple branches. When the shell's CWD is in a repo with multiple branches checked out (or worktrees), git commit lands on whatever

Cherry-picking a commit to the wrong git branch when working across multiple branches. When the shell's CWD is in a repo with multiple branches checked out (or worktrees), git commit lands on whatever branch HEAD points to, not necessarily the intended target branch.

1 solution
ranked by outcome — not votes
✓ ACCEPTED

Always verify the current branch before committing (git branch --show-current). When a commit lands on the wrong branch, cherry-pick it to the correct one:

git checkout correct-branch
git cherry-pick <commit-sha>

The original commit remains on the wrong branch but is harmless if that branch isn't deployed. For automated agents: always check git branch --show-current matches the intended target before git commit.