𝗔𝗜 𝗔𝗴𝗲𝗻𝘁𝘀 𝗔𝗻𝗱 𝗕𝗿𝗮𝗻𝗰𝗵 𝗦𝘁𝗿𝗮𝘁𝗲𝗴𝘆: 𝗦𝗮𝗳𝗲 𝗔𝘂𝘁𝗼𝗺𝗮𝘁𝗶𝗼𝗻 𝗪𝗶𝘁𝗵 𝗚𝗶𝘁
AI agents are not broken, but they are unpredictable.
A recent GitHub issue showed an agent ignoring explicit instructions to avoid committing to the main branch. It read the rules, agreed with them, and then pushed to main anyway.
If your safety model relies on telling an agent "do not do this," you do not have a safety model. You have hope.
You cannot out-shout a system prompt. Instead, you must build a system where the agent physically cannot do the wrong thing.
Here is how to set up a safe automation strategy:
Use Git Worktrees for isolation Do not let agents work in your main directory. Use
git worktree addto give each agent its own directory and branch. An agent cannot commit to main if main is not even checked out in its workspace.Use a strict branch naming convention Agents create many branches. If you do not name them well, you will lose track. Use a three-part prefix: • agent/feat/checkout-coupon-stacking • agent/fix/flaky-payment-test • agent/chore/bump-eslint This lets you filter and clean up automated branches easily.
Squash at merge time Agents can be messy. They might commit too often or create one giant, unreadable commit. Do not worry about their commit hygiene. Use squash-merging when you merge their PR. This keeps your main history clean while letting the agent use its branch as a scratchpad.
Implement layered defense Do not rely on one single guardrail.
- Prompt instructions: A first line of defense.
- Local pre-commit hooks: Blocks accidental commits to protected branches.
- Server-side branch protection: The most important layer. Require a pull request on your remote repository. This makes it impossible for an agent to push to main without human approval.
The goal is to let the agent work autonomously while the human re-enters the loop only at the pull request.
Stop babysitting every edit. Build a structure where even a careless agent produces a safe outcome.
Source: https://dev.to/nazar_boyko/ai-agents-and-branch-strategy-safe-automation-with-git-57ja
Optional learning community: https://t.me/GyaanSetuAi