branch-flow-gate
Skill8 starsChanged 6 months agoMITView on GitHub
Trusted-advisor gate for branch and PR hygiene. Auto-invokes when the user mentions creating a branch, opening a PR, shipping/promoting/deploying, cherry-picking, rebasing, hotfixing, or back-syncing. Suggests and explains in-script (preflight always exits 0) and writes a .branch-flow-cleared sentinel that pre-push Gate 3 hard-consumes on pushes to dev/main. Three escape hatches: per-branch ack file (touch .git/base-advisory-ack-<branch>), GIT_BASE_OVERRIDE=1 env var, or use an exempt prefix (hotfix/, release/, backport/, tagged-release/) which is exempt from the base-alignment advisory and typically does not target dev/main. Multi-team config via .git-guidance.yml (currently only default_base is read). Uses git first-parent chain to verify branch base (not naive merge-base). Advises on retry-suffix branches (-vN), back-sync/mirror naming, server-regex compliance, anti-leak fixtures, and loop-on-identical-error retries.
- Commits and pushes
In this repository129 other files it gives its agents.
- AGENTS.mdAGENTS.md
- guidance/AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- guidance/CLAUDE.mdCLAUDE.md
- .github/copilot-instructions.mdCopilot instructions
- blast-radius-checkSkill
- brainstormingSkill
- branch-sync-gateSkill
- codebase-reconSkill
- codeowners-drift-auditSkill
- code-review-batterySkill
- cognitive-complexity-refactoringSkill
- debateSkill
- debug-conductorSkill
- dispatching-parallel-agentsSkill
- domain-buildSkill
- evidence-adjudicatorSkill
- executing-plansSkill
- external-cli-auditSkill
- feature-developmentSkill
- field-rename-verificationSkill
- finishing-a-development-branchSkill
- git-branch-conventionsSkill
- gitlab-cliSkill
- hotfix-charterSkill
- implementation-trackerSkill
- incident-revert-reviewSkill
- infra-config-investigatorSkill
- investigation-stateSkill
- kernel-splitSkill
- llm-behavior-investigatorSkill
- llm-skill-reviewSkill
- merge-authorization-gateSkill
- micro-harsh-reviewSkill
- output-verificationSkill
- pre-commit-gateSkill
- progressive-code-review-gateSkill
- progressive-harsh-reviewSkill
- providing-code-reviewSkill
- pr-triage-gateSkill
- push-authorization-gateSkill
- receiving-code-reviewSkill
- reproduction-experiment-investigatorSkill
- requesting-code-reviewSkill
- requirements-validation-pmSkill
- requirements-validationSkill
- scope-tripwireSkill
- session-handoffSkill
- skills-hierarchy-tuningSkill
- sp-bughuntSkill
- state-consistency-investigatorSkill
- subagent-driven-developmentSkill
- systematic-debuggingSkill
- test-driven-developmentSkill
- timeline-trace-investigatorSkill
- token-estimationSkill
- unified-commit-gateSkill
- using-git-worktreesSkill
- using-superpowersSkill
- verification-before-completionSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
4 rules. About 0 are common, 3 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 87
When the user mentions any of these in conversation, this skill activates before the action and advises.
- Distinctive: line 100
ALL advisories print a soft message and exit 0.
- Distinctive: line 114
Document the reason in your PR description.
- Very specific: line 137
Always exits 0. Writes .branch-flow-cleared sentinel that pre-push Gate 3 consumes on pushes to dev/main.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
branch-flow-gate -- Trusted Advisor (auto-invoked)
Wrong skill? Branch-name regex check alone ->
git-branch-conventions. Pull before resuming work ->branch-sync-gate. Per-team flow specifics -> team's own documentation.
Announce at start: "I'm using branch-flow-gate to advise on branch hygiene. (Auto-invoked by intent. The preflight script never blocks; the sentinel it writes is consumed by pre-push Gate 3 on pushes to dev/main.)"
Core Principle
This skill strongly recommends branching patterns that keep teams aligned but never mandates or precludes deviation when a developer has a valid reason. Every advisory exits 0 from the skill / preflight script. Every advisory includes an explicit escape hatch.
Honest disclosure -- this is advisory in-script, hard-blocking at push time. The preflight writes a
.branch-flow-clearedsentinel which is consumed bypre-pushGate 3 on pushes todev/main. Without a valid sentinel for the pushed SHA, Gate 3 refuses the push. Hotfix/release/backport branches don't push to those canonical targets so are de-facto exempt; if your flow pushes hotfixes directly tomain, use ahotfix/*branch name (auto-exempt) or setGIT_BASE_OVERRIDE=1.
Auto-Invocation
This skill fires on intent:
- Creating a branch (
checkout -b,git checkout -B, "branch off ...") - Opening a PR/MR ("open a PR", "merge request", "ready to merge")
- Shipping ("ship this", "deploy", "push to prod", "release", "promote ...")
- Cross-environment moves ("cherry-pick", "back-sync", "forward-port", "rebase onto ...")
- Hotfix / revert language
When the user mentions any of these in conversation, this skill activates before the action and advises.
What It Advises On
| Check | When it fires | What it suggests |
| Base alignment | Branch is not on the required base's first-parent chain | Rebase onto the recommended base, OR acknowledge if the deviation is intentional |
| Retry suffix | Branch name ends in -vN | Recover the original branch via amend + force-with-lease |
| Back-sync / mirror naming | Name matches back-sync/*, sync/*, mirror/*, etc. | Use forward-port semantics (branch off destination, pull source forward) |
| Anti-leak patterns | Diff contains literal <word>-internal-*, *-secret-*, etc. | Use FAKE-LEAK-PATTERN-FOR-TEST placeholder |
| Non-ASCII in diff | Added lines contain non-ASCII | GitLab ASCII-only commit-msg hook may reject |
| Identical error loop | Two consecutive opaque errors after retry | STOP and diagnose before retrying again |
ALL advisories print a soft message and exit 0. The script never blocks.
Escape Hatches (in order of permanence)
- Per-branch acknowledgement (most common):
The advisory will not repeat for this branch.touch ".git/base-advisory-ack-<branch-slug>" - One-shot override (when you know what you're doing this time):
Document the reason in your PR description.GIT_BASE_OVERRIDE=1 git push Exempt prefix (documented deviation lane):
hotfix/*(emergency production patch)release/*(release branch)backport/*(backporting to older release)tagged-release/*(release-tag work)
Branches with these prefixes skip the base advisory entirely.
Mandatory Preflight (BEFORE every branch creation or PR)
# Auto-mode (checks current branch against required base from config):
tools/branch-flow-preflight.sh
# Explicit pair-mode:
tools/branch-flow-preflight.sh "<source-branch>" "<target-branch>"
# Identical-error stop helper:
tools/branch-flow-preflight.sh --identical-check "$ERR1" "$ERR2"Always exits 0. Writes .branch-flow-cleared sentinel that pre-push Gate 3 consumes on pushes to dev/main. The sentinel must match the pushed commit's SHA; missing or stale (SHA-mismatched) sentinels == refused push.
Multi-Team Config
For repos with heterogeneous flows, commit .git-guidance.yml at the repo root:
default_base: origin/devCurrently only default_base: is read. A richer per-team mapping (with teams: and per-team exempt_prefixes:) is planned but not yet implemented in tools/branch-flow-preflight.sh. Until then, legacy teams needing a different base must set it as the repo-wide default_base and use the hardcoded exempt prefixes (hotfix/, release/, backport/, tagged-release/).
Hook Installation (advisory; not required)
To get advisory output automatically:
Lefthook (lefthook.yml):
post-checkout:
commands:
branch-base-advisory:
run: ./tools/branch-flow-preflight.sh
pre-push:
commands:
branch-base-advisory:
run: ./tools/branch-flow-preflight.shHusky (package.json):
"husky": {
"hooks": {
"post-checkout": "./tools/branch-flow-preflight.sh",
"pre-push": "./tools/branch-flow-preflight.sh"
}
}post-checkout fires once when the branch is created (before any work is invested). pre-push fires once per push (last local chance to notice). Neither of these advisory hooks blocks.
Note: This repo's
tools/pre-push(installed viatools/install-hooks.sh) is the authoritative path. It runs Gate 3 which consumes.branch-flow-clearedand does block when the sentinel is missing/stale on pushes to dev/main. The Lefthook/Husky integrations above are for contributors who want advisory output earlier in the workflow; they do not replace the in-tree hook. Iftools/pre-pushis not installed in this clone, Gate 3 does not fire and pushes to dev/main rely entirely on PR review -- see reference.md F10. Server-side enforcement (CI runners, merge-queue automation, bot merges) requires a server-side hook or branch-protection rule -- the local sentinel does not propagate.
Anti-Patterns to Avoid (in the skill, not the user)
exit 1in a guidance hook -- if it can block, it's enforcement, not guidance.- Repeating the advisory on every checkout -- once per branch, at creation. Repetition trains dismissal.
- No escape hatch -- a tool with no override breeds resentment.
- Not suppressing
hotfix/*-- every advisory tool that fires on emergencies loses developer trust. - Raw
merge-basewithout first-parent filtering -- false negatives when dev/main share recent history. - Blocking CI status check -- surface advisories as PR annotations or comments, never required checks.
- Cascade-chasing after a promotion -- after a dev->main promotion lands, do exactly one forward-port PR (main->dev) and STOP. Each forward-port adds a merge commit the source is now "behind" on; chasing that gap with another forward-port creates the next gap and so on infinitely. Equal trees = aligned, even with topology drift. See reference.md F11.
When the Advisory Should Be Heeded vs. Ignored
| Situation | Action |
| Just-branched feature off dev | Advisory should be quiet (or PASS) |
| Forgot to fetch + dev moved -> stale-but-correct base | Advisory says "rebase recommended"; you can ignore for now |
| Cut from a stale integration branch because of an integration test | Heed the advisory and rebase OR acknowledge with touch .git/base-advisory-ack-<branch> |
| P0 hotfix at 3am off main | Use hotfix/ prefix; advisory exempts |
Renaming -v2 retry to canonical name | Heed and git branch -m; recover via amend + force-with-lease |
Companion Skills
branch-sync-gate-- pull-gate (REQUIRED before this skill)git-branch-conventions-- branch-name regex checkfinishing-a-development-branch-- handoff ceremonyprogressive-code-review-gate-- cr-battery + sentinel
Failure Modes
See reference.md for the catalogue and concrete advisory examples.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

