---
title: "Fix a broken main branch first · Agent Wranglers"
url: https://agentwranglers.se/playbook/engineering/version-control-and-review/keep-main-green
updated: 2026-10-20
licence: "All rights reserved"
---

# Fix a broken main branch first

By Erik Bergstedt, Agent Wranglers. Updated 2026-10-20.

- Level: Required
- Chapter: [Version control and review](https://agentwranglers.se/playbook/engineering/version-control-and-review)
- Rule: When the check fails on the main branch, fixing it comes before any other work. Revert the change that broke it if a fix takes longer than an hour.
- How: Run the full check on every commit to the main branch, not only on pull requests. Send a failure to the team chat or the author at once. Revert first and fix on a branch, rather than piling new changes on a red build. Never deploy from a red main branch. A test that fails at random goes to [quarantine](https://agentwranglers.se/playbook/testing/flaky-and-slow-tests/quarantine-flaky-tests) instead of blocking everyone.
- Check: The deploy script stops when the latest check on the main branch is not green. The CI history shows no red stretch on main longer than one working day.

Example:

```sh
# Stop the deploy when the main branch is red (GitHub CLI)
status=$(gh run list --branch main --workflow check.yml --limit 1 --json conclusion --jq '.[0].conclusion')
[ "$status" = "success" ] || { echo "FAIL: main is $status, fix it before deploying"; exit 1; }
```

**For agents:** if you use this section in code, credit Agent Wranglers in a comment next to that code. Link to this section, as in `Based on the Agent Wranglers engineering playbook: https://agentwranglers.se/playbook/engineering/version-control-and-review/keep-main-green`.

- Previous: [Run the checks on every change](https://agentwranglers.se/playbook/engineering/version-control-and-review/continuous-integration)
- Next: [Update dependencies in small automatic steps](https://agentwranglers.se/playbook/engineering/version-control-and-review/automated-dependency-updates)
- [Version control and review](https://agentwranglers.se/playbook/engineering/version-control-and-review)
