This is the default Git workflow for agent-driven repositories.
mainis the protected trunk.- All meaningful work happens on short-lived branches.
- Default merge strategy is squash merge unless the repo explicitly preserves multi-commit history.
- Agents do not work directly on
main.
Always start from the remote default branch, not a possibly stale local branch.
git fetch origin
git switch --detach origin/main
git switch -c <branch-name>git fetch origin
git worktree add .worktrees/<slug> origin/main
cd .worktrees/<slug>
git switch -c <branch-name>Use git worktree when parallel PRs must exist at the same time. Do not stack unrelated local branches in one checkout.
git add <files>
git commit -m "<type>(<scope>): <summary>"Rules:
- commit only in-scope files
- keep commits reviewable
- do not bundle unrelated workspace dirt
- each commit should leave the branch in a coherent state
git fetch origin
git rebase origin/mainIf the branch was already pushed:
git push --force-with-leaseUse --force-with-lease, never --force.
Before claiming a branch is PR-ready:
git fetch origin
git rev-parse HEAD
git rev-parse origin/main
git log --oneline origin/main..HEAD
git diff --stat origin/main..HEAD
git status --shortThe diff against origin/main should contain only the scoped work.
git fetch origingit rebase origin/main- resolve conflicts deliberately
- rerun validation
git push --force-with-leaseif needed
Do not blindly accept ours or theirs without understanding the behavior change.
main should require:
- pull requests before merge
- required status checks
- resolved review conversations
- at least one approval
If the repository volume justifies it, add merge queue on top of branch protection.
| Situation | Allowed? | Default |
|---|---|---|
| private local cleanup before PR exists | Yes | allowed |
| branch rebased before review starts | Yes | allowed with --force-with-lease |
| active review in progress | Avoid | prefer follow-up commits unless the repo requests a history rewrite |
main |
No | forbidden |
Use the least destructive tool that solves the problem.
git revert <commit>for undoing merged historygit cherry-pick <commit>for transplanting a known-good changegit stash -ufor short-lived local context switches
Avoid destructive commands like git reset --hard unless the repo owner explicitly approves it.