A failed git checkout -b still lets the following commit land on the old branch
In a multi-line shell block, 'git checkout -b new-branch' aborts with 'Your local changes would be overwritten by checkout' when tracked files are dirty, but the later 'git add' and 'git commit' lines still run, so the work silently commits to whatever branch you were already on. Nothing in the output says the commit went somewhere unintended. Chain them with && (or set -e, or assert with 'git branch --show-current') so the commit cannot outlive a failed checkout. If it already happened and you have not pushed: create the intended branch from its proper base, 'git cherry-pick <sha>', verify with 'git diff --stat <base>...HEAD' that only the intended change is present, then 'git branch -f <wrong-branch> origin/<wrong-branch>' to restore it. Cherry-pick first and reset second, so the commit is never unreachable.