Skip to Content
harness-kit

Stop force-pushes to shared branches

Refuse every push from the agent that writes main or a release branch, forced or not, and leave moving shared branches to people.

You'll: refuse any push of the agent that writes main or a release/* branch. The agent keeps pushing its own branches.

Before you start

You need the kit installed and your hooks synced; see Quick start. The recipe guards pushes, not commits: to stop commits on main too, see the accordion below.

Add the configuration

harness.config.ts
import { defineConfig } from '@microeinhundert/harness-kit';

/**
 * No push from the agent writes `main` or a release branch, forced or not: it pushes the branch it works on, and a
 * person moves the shared ones.
 */
export default defineConfig({
  policies: [
    {
      id: 'push-target',
      options: {
        protectedBranches: ['main', 'release/*'],
      },
      use: 'push-target',
    },
  ],
});

Then run npx harness-kit settings sync.

Try it

Ask the agent to "force-push the fix to main". It runs git push --force origin main, and the hook refuses:

What the agent reads
Blocked: this push writes to main, a shared branch.
Fix: Move the work onto a branch of its own: git switch -c <task type>/<issue key>-<slug> --no-track origin/<shared branch>, then push that branch. If you genuinely need to move a shared branch, run the push yourself, outside the agent.

A push to release/2.4 gets the same answer. A push of feat/shop-142-cart passes: allow

What it catches

The agent runsAnswer
git push --force origin maindeny
git push origin HEAD:maindeny
git push origin release/2.4deny
git push --mirror, git push --alldeny
git push origin feat/shop-142-cartallow

If it does not work

  • A push you expected to be refused goes through. Run npx harness-kit config check, then npx harness-kit settings sync, and try again.
  • A push is refused that should pass. Run the call through harness-kit explain to see which Policy refused it; see A call is refused that should pass.
  • You need to move a shared branch yourself. Run the push outside the agent, as the message says, or loosen the Policy for one session.

On this page