git-flow
Overview
A guided workflow that takes changes from the working tree to a pull request, following consistent conventions: branch naming, code review, Conventional Commits, automatic SemVer, and a PR template. Guided, not blind — confirm with the user at the review, doc-update, and PR steps.
When to Use
- Changes are done and ready to be committed and shared.
- User says "ship this", "commit and open a PR", "create the PR".
- A feature or fix is finished and needs a branch + commit + PR.
Skip when: the user only wants a quick local commit with no review/PR.
Conventions
| Aspect | Rule |
|---|---|
| Branch | type/description, kebab-case (e.g. feat/login-form) |
| Commit | Conventional Commits, in English |
| Types | feat, fix, docs, style, refactor, perf, test, build, ci, chore |
| SemVer (≥ 1.0) | feat → minor · fix → patch · BREAKING CHANGE (or !) → major |
| Other types | docs/style/refactor/perf/test/build/ci/chore → patch |
SemVer (0.x) |
BREAKING → minor (0.y→0.(y+1), resets patch) · everything else → patch |
| PR base | develop if that branch exists (local or on the remote), else main |
| Tag | Created after the PR merges, and only if that merge's base was main — a merge into develop is not a release, see step 10 |
| PR | Via gh, ask before creating |
Rules & tie-breakers
- One authoritative type. Classify the change ONCE (step 2). That type drives the branch name, the commit, and the SemVer bump. They must agree.
- Mixed changes: pick the highest-impact type for the version
(
BREAKING>feat>fix> everything else). If the diff contains clearly separate logical changes, make separate commits; otherwise one commit. - Pre-1.0 (
0.x.y): SemVer is still unstable, so the normal table does NOT apply. ABREAKING CHANGE/!bumps the minor (0.2.3→0.3.0);feat,fix, and every other type bump the patch (0.2.3→0.2.4). Use the ≥ 1.0 rules only once the project actually reaches1.0.0. - Branch description: kebab-case derived from the commit subject, ≤ 5 words
(e.g. subject "add token refresh on 401" →
feat/token-refresh). - Version source precedence:
package.json→VERSION→ latestgit tag→CHANGELOG.md. Strip a leadingv. If two sources disagree, use the highest. If no source records a version, start from0.1.0and createCHANGELOG.md. - Staging: only stage the reviewed files plus the docs you updated. Never
git add -A/git add .blindly. - Remote: never hardcode
origin. Resolve the push remote fromgit remote -v— prefer the current branch's upstream if one is set, else the sole remote, else ask which to use. Some repos push through an SSH-alias remote (e.g.git@host-alias:org/repo.git) whose name is notorigin. Use the resolved remote name for the push (step 9) and the post-merge tag (step 10). - Changes = tracked modifications (staged or unstaged) and/or new files. Whitespace-only or no changes → stop.
Workflow
Run in order. Stop and report if a precondition fails.
- Detect context —
git status/git diff; stop if no changes. Detect version files (package.json,VERSION,CHANGELOG.md,README.md). Resolve the push remote (git remote -v; see the Remote rule). Detect whether adevelopbranch exists (git show-ref --verify --quiet refs/heads/developorrefs/remotes/<remote>/develop) — if so, it's the PR base for this run (GitFlow repo); otherwise the base ismain. Checkgh auth status. - Classify — pick the one Conventional Commit type and the SemVer bump (see Conventions + tie-breakers).
- Create branch — if on
main/master,git switch -c type/description. If already on a work branch, keep it. - Code review — review the diff for bugs, convention issues, and simplifications. Show findings; continue after the user's OK.
- Verify — detect the project's test/lint command and run it (see
references/verify-commands.mdfor the per-ecosystem mapping). Prefer a command the repo already defines (scripts,Makefiletargets, CI) over a generic guess. Stop and report if it fails; continue once green. If the project has no test/lint setup, say so and move on — don't fabricate a command. - Compute version — read current version per precedence, then apply the
bump with
scripts/next-version.sh <current> <type>(the canonical, tested implementation of the SemVer table, including the0.xrule). The Conventions table stays the human-readable reference. - Validate & update docs — list the files to update and show the user
before staging:
CHANGELOG.md: add## [X.Y.Z] - YYYY-MM-DDwith the right section (Added/Changed/Fixed/etc.); replace an[Unreleased]block if present.- Version in
package.json/VERSIONif they exist. README.mdonly if the change affects documented behavior. Apply after confirmation.
- Stage & commit —
git addthe relevant files; Conventional Commit message in English. Scope optional (derive from path only if obvious). - Push & PR (ask first) —
git push -u <remote> <branch>(the remote resolved in step 1). Build the PR body fromreferences/pr-template.md(if missing, use a minimal Summary/Changes/Version body). PR base is the branch resolved in step 1 (developif it exists, elsemain), title = commit subject. Show the body and ask before creating. On confirmation:gh pr create --base <resolved base>. Ifghis unavailable, output the body and the compare URL instead. - Tag after merge — once the PR is merged, tag only if its base was
main:git tag -a vX.Y.Z -m "vX.Y.Z"andgit push <remote> vX.Y.Z. Skip if the tag already exists. If the base wasdevelop, don't tag here — that merge is an integration step, not a release; the tag happens later whendevelopis promoted tomain(release/hotfix branch), which is outside this skill's scope.
Common Mistakes
- Tagging on the feature branch — the tag goes on
mainafter merge (step 10). - Tagging a
developmerge — only tag when the PR's base wasmain; a merge intodevelopis an integration step, not a release. - Hardcoding PR base to
main— detect adevelopbranch first (step 1); GitFlow repos merge feature branches intodevelop, notmain. - Committing on
main— branch first (step 3) unless already on a work branch. - Assuming
package.json— follow the version-source precedence; detect first. - Hardcoding
origin— resolve the real remote (step 1); some repos use an SSH-alias remote. - Over-bumping a
0.xproject — pre-1.0,featis a patch and a breaking change is a minor. - Skipping tests — run the project's test/lint command (step 5) before committing.
git add -A— stage only reviewed + updated files.- Spanish commit/PR text — commits and PR are English; only the chat is Spanish.
- Staging before showing doc updates — show changes in step 7 before
git add.
PR Template
See references/pr-template.md.