Skip to content

implement: check branch isn't merged before committing #1216

Description

@tomermurray

Before filing

  • I've read SCOPE.md and checked .out-of-scope/, and this isn't covered by either.

Skill

implement

What went wrong

Found with the /retro skill, reviewing four sessions of a Python project. Harness: Claude Code (VS Code extension). Model: Opus 5.5 High.

I ran /implement on a feature. The checked-out branch, had already been merged into master and deleted on the remote, but the local branch still existed. /implement ends with "Commit your work to the current branch", so it committed the whole feature there. I had to stop the agent and tell it: "you need to put it on a different branch please, this branch is already merged and deleted". The agent then cherry-picked the commit onto a new branch from origin/master and deleted the dead local branch.

Nothing in the skill could have caught this: the branch looks normal locally, and the skill gives the agent no reason to doubt it. It is easy to hit with merge-and-delete branch flows when a new session starts in the same checkout.

Proposed change

Add one step to /implement, before the first commit:

Before the first commit, check the current branch isn't already merged.
  git fetch --prune
  git merge-base --is-ancestor HEAD origin/<default-branch>
If it is an ancestor, its work is already in <default-branch>: create a new branch
from origin/<default-branch>, carry the uncommitted work over, and tell the user
in one line.

Detect <default-branch> with git symbolic-ref refs/remotes/origin/HEAD instead of hard-coding main or master. If the current branch is the default branch itself, keep the existing "branch first" behaviour.

Edit the line "Commit your work to the current branch." to "Commit your work to the current branch (once it has passed the merged-branch check above)."

Remove nothing.

Activity

  1. added
    unsureTriage couldn't decide; awaiting Matt
    and removed
    needs-triageMaintainer needs to evaluate
    on Oct 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    unsureTriage couldn't decide; awaiting Matt

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions