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
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:
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 runs | Answer |
|---|---|
git push --force origin main | deny |
git push origin HEAD:main | deny |
git push origin release/2.4 | deny |
git push --mirror, git push --all | deny |
git push origin feat/shop-142-cart | allow |
If it does not work
- A push you expected to be refused goes through. Run
npx harness-kit config check, thennpx harness-kit settings sync, and try again. - A push is refused that should pass. Run the call through
harness-kit explainto 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.
Related
- Git and forge: every git Policy and its options.
- Overrides: let a person loosen the Policy for one session.