A cart rounding fix is ready for review, but it sits on the same branch as an unfinished coupon field. Git pushes the history the destination needs to reach a commit, so pushing the fix by its ID can also send the earlier coupon work. Copy the fix onto a branch that starts at the remote destination instead.
Find the commit and fetch the destination
In acme/web, the fix is on work/cart and the destination is the existing branch review/cart on origin. Use your own names. Check that origin has one push URL and that it matches the fetch URL. Run these steps from the repository root in the same terminal and stop if a command fails.
dest=refs/heads/review/cart
git fetch --no-tags --no-prune \
--no-prune-tags origin "$dest" &&
base=$(git rev-parse --verify \
FETCH_HEAD) &&
git log --oneline "$base"..work/cart
a505488 Fix cart rounding
54940dc Start coupon field
Inspect the fix with git show a505488. Use the ID from your own log. Continue if it is a regular commit that can stand on its own. A patch can apply cleanly and still depend on code from the earlier commit.
Copy the fix into a separate worktree
git worktree add -b send/cart-fix \
../web-cart-fix "$base" &&
cd ../web-cart-fix &&
git cherry-pick a505488
Git creates a new commit with the fix on send/cart-fix. The original branch and its working files stay in the original folder. If the cherry-pick hits a conflict, run git cherry-pick --abort in the new worktree and check whether the fix needs changes from another commit.
Review and push the one outgoing commit
fix=$(git rev-parse --verify HEAD) &&
git log --oneline "$base".."$fix" &&
git diff "$base" "$fix"
The log should show one line, Fix cart rounding, with a new ID. Read the diff and run the relevant tests in the new worktree. For a closer look, see how to preview commits before you push.
The next command checks that the commit you reviewed has exactly one parent, the fetched tip. The push lease then requires the remote branch to still point to that same tip. Together, those checks keep the push to one commit, even if someone rewound the branch after you fetched it.
test -n "$base" &&
test "$(git show -s --format=%P \
"$fix")" = "$base" &&
git push --no-follow-tags origin \
--force-with-lease="$dest:$base" \
"$fix:$dest"
If the parent check fails, stop and check which commit you reviewed and where the worktree started. If Git rejects the push because the destination moved, fetch it again and repeat the copy and checks from its new tip. Use a fresh worktree path and branch name.
Check the original branch
git log --oneline "$base"..work/cart
The log still shows Fix cart rounding and Start coupon field with their original IDs. To relocate commits you made on the wrong branch, see how to move unpushed commits to another branch.
See what’s waiting on each branch
push& (Pushand) shows the commits waiting on each branch in your Mac menu bar. Open the changes to review what the branch will send before you push it.