Git Workflow
Purpose
Keep repository history readable and automation-friendly: trunk-based branches,
Conventional Commits that drive versioning and release notes (ci-cd consumes
them), and pull requests small enough to review honestly.
When to Use / When NOT to Use
Use when:
- Committing changes ("write the commit message", "split this into commits").
- Opening, structuring, or cleaning up a pull request.
- Deciding branching strategy for a repo or a release train.
Do NOT use when:
- The commit content itself needs review — that is
code-quality/code-review
(this skill governs the shape of history, not the code in it).
- An incident fix must bypass normal flow — the emergency path in
incident-response
still uses Conventional Commits, just with expedited review.
Prerequisites & Assumptions
- Trunk-based development:
main is always releasable; branches live < 2 days;
feature flags hide unfinished work.
- Conventional Commits types:
feat, fix, docs, refactor, test,
chore, ci, perf, build, revert — with optional scopes
(feat(orders):).
- Semantic versioning is derived from commits by release automation (
ci-cd).
Step-by-Step Workflow
- Branch from main — name
feat/<ticket>-short-slug, fix/<ticket>-slug,
or chore/<slug>; one logical change per branch.
- Commit in logical units — each commit compiles and passes tests; message
per the format below; split mixed changes (refactor vs feature) into separate
commits.
- Open the PR early and small — target ≤ 400 changed lines; description
states what/why, test evidence, and risk; link the issue.
- Keep it green and current — rebase onto main regularly; resolve conflicts
as the author; never merge a red pipeline (
ci-cd gates).
- Merge — squash-merge for features (history reads as one logical change
with the Conventional Commit title), merge commits only for release trains;
delete the branch.
- Revert, don't bury — a bad change is reverted with
revert: <original subject>; history is never rewritten after push.
Enterprise Rules & Standards (MUST / MUST NOT)
- MUST use Conventional Commits:
<type>(<scope>): <imperative summary ≤72 chars> + body explaining why +
BREAKING CHANGE: footer when APIs break; drives SemVer automation.
- MUST keep
main releasable at all times; every commit on it passes the
full gate.
- MUST squash-merge feature branches so history is one logical change.
- MUST keep PRs ≤ 400 changed lines (split with stacked PRs if larger) and
short-lived (< 2 days).
- SHOULD write commit bodies for anything non-obvious: context, trade-offs,
and the reason it is safe.
- SHOULD sign commits (
gpg/ssh signing) where the org requires
provenance.
- MUST NOT rewrite published history on shared branches.
- MUST NOT commit secrets, large binaries, or generated artifacts (use the
artifact store and
security secret rules).
- MUST NOT merge with unresolved review threads or bypass a failing gate.
Examples
Good — Conventional Commit with body and breaking-change footer:
feat(orders): make cancel idempotent
Clients retry cancels on flaky networks and were double-cancelling.
Cancel now accepts an Idempotency-Key header and returns the original
result for replays within 24h.
BREAKING CHANGE: Cancel without an Idempotency-Key returns 400.
Bad — the useless message:
fixed stuff
Checklist
Common Pitfalls
- The 3,000-line PR — unreviewable, ships defects; stack small PRs instead.
- "WIP" branches aging into cheese — weeks-old branches full of conflicts;
branch < 2 days and flag unfinished work.
- Merge-commit soup — interleaving merge commits on feature branches; rebase
locally, squash on merge.
git push --force on shared branches — destroys teammates' work; force
only on your own unmerged branch, with --force-with-lease.
References
1---2name: git-workflow3description: 'Governs branches, Conventional Commits, and pull-request discipline — trunk-based flow, commit hygiene, and PR standards. Trigger with "write the commit message", "how should we branch", or "clean up this PR before review".'4metadata:5 source: https://skillmd.com/skills/pnguyen215/git-workflow6---78# Git Workflow910## Purpose1112Keep repository history readable and automation-friendly: trunk-based branches,13Conventional Commits that drive versioning and release notes (`ci-cd` consumes14them), and pull requests small enough to review honestly.1516## When to Use / When NOT to Use1718Use when:1920- Committing changes ("write the commit message", "split this into commits").21- Opening, structuring, or cleaning up a pull request.22- Deciding branching strategy for a repo or a release train.2324Do NOT use when:2526- The commit content itself needs review — that is `code-quality/code-review`27 (this skill governs the shape of history, not the code in it).28- An incident fix must bypass normal flow — the emergency path in `incident-response`29 still uses Conventional Commits, just with expedited review.3031## Prerequisites & Assumptions3233- Trunk-based development: `main` is always releasable; branches live < 2 days;34 feature flags hide unfinished work.35- Conventional Commits types: `feat`, `fix`, `docs`, `refactor`, `test`,36 `chore`, `ci`, `perf`, `build`, `revert` — with optional scopes37 (`feat(orders):`).38- Semantic versioning is derived from commits by release automation (`ci-cd`).3940## Step-by-Step Workflow41421. **Branch from main** — name `feat/<ticket>-short-slug`, `fix/<ticket>-slug`,43 or `chore/<slug>`; one logical change per branch.442. **Commit in logical units** — each commit compiles and passes tests; message45 per the format below; split mixed changes (refactor vs feature) into separate46 commits.473. **Open the PR early and small** — target ≤ 400 changed lines; description48 states what/why, test evidence, and risk; link the issue.494. **Keep it green and current** — rebase onto main regularly; resolve conflicts50 as the author; never merge a red pipeline (`ci-cd` gates).515. **Merge** — squash-merge for features (history reads as one logical change52 with the Conventional Commit title), merge commits only for release trains;53 delete the branch.546. **Revert, don't bury** — a bad change is reverted with55 `revert: <original subject>`; history is never rewritten after push.5657## Enterprise Rules & Standards (MUST / MUST NOT)5859- **MUST** use Conventional Commits:60 `<type>(<scope>): <imperative summary ≤72 chars>` + body explaining _why_ +61 `BREAKING CHANGE:` footer when APIs break; drives SemVer automation.62- **MUST** keep `main` releasable at all times; every commit on it passes the63 full gate.64- **MUST** squash-merge feature branches so history is one logical change.65- **MUST** keep PRs ≤ 400 changed lines (split with stacked PRs if larger) and66 short-lived (< 2 days).67- **SHOULD** write commit bodies for anything non-obvious: context, trade-offs,68 and the reason it is safe.69- **SHOULD** sign commits (`gpg`/`ssh` signing) where the org requires70 provenance.71- **MUST NOT** rewrite published history on shared branches.72- **MUST NOT** commit secrets, large binaries, or generated artifacts (use the73 artifact store and `security` secret rules).74- **MUST NOT** merge with unresolved review threads or bypass a failing gate.7576## Examples7778Good — Conventional Commit with body and breaking-change footer:7980```text81feat(orders): make cancel idempotent8283Clients retry cancels on flaky networks and were double-cancelling.84Cancel now accepts an Idempotency-Key header and returns the original85result for replays within 24h.8687BREAKING CHANGE: Cancel without an Idempotency-Key returns 400.88```8990Bad — the useless message:9192```text93fixed stuff94```9596## Checklist9798- [ ] Branch named by type + ticket, branched from latest main.99- [ ] Each commit compiles, passes tests, and follows Conventional Commits.100- [ ] PR ≤ 400 changed lines, description has what/why/test evidence.101- [ ] Pipeline green; review threads resolved before merge.102- [ ] Squash-merge applied; branch deleted.103- [ ] Breaking changes carry a `BREAKING CHANGE:` footer and a version bump.104105## Common Pitfalls106107- **The 3,000-line PR** — unreviewable, ships defects; stack small PRs instead.108- **"WIP" branches aging into cheese** — weeks-old branches full of conflicts;109 branch < 2 days and flag unfinished work.110- **Merge-commit soup** — interleaving merge commits on feature branches; rebase111 locally, squash on merge.112- **`git push --force` on shared branches** — destroys teammates' work; force113 only on your own unmerged branch, with `--force-with-lease`.114115## References116117- Conventional Commits: https://www.conventionalcommits.org/118- Semantic Versioning: https://semver.org/119- Trunk-Based Development: https://trunkbaseddevelopment.com/120- GitHub — squashing commits: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/incorporating-changes-from-a-pull-request/about-pull-request-merges