agentleFS
kayamankayaman/skills/git-best-practices/SKILL.md

git-best-practices

Skill3 starsChanged 8 months agoCC0-1.0View on GitHub

Enforces Git workflow best practices including trunk-based development, conventional commits, atomic commits, small pull requests, and Git hooks. Use when choosing a branching strategy, writing commit messages, structuring pull requests, configuring Git hooks and CI pipelines, managing feature flags, or setting up semantic versioning automation.

1 other project uses a version of this.

Adopted by

Most recently taken up by

The file

Show its rules and text

We split this skill into the rules it gives an agent

18 rules. About 0 are common, 18 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈18

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    All developers collaborate on a single branch (trunk/main).

    line 25
  2. Distinctive:

    SHOULD default to trunk-based development — DORA research confirms higher-performing organizations are more likely to use TBD

    line 32
  3. Distinctive:

    MUST keep feature branches to 1–2 days maximum.

    line 33
  4. Distinctive:

    MUST use feature flags to decouple deployment from release when features span multiple days

    line 34
  5. Distinctive:

    MUST remove release toggles promptly after the feature is fully launched

    line 56
  6. Distinctive:

    SHOULD track all active flags and assign cleanup owners

    line 57
  7. Distinctive:

    Do not end the subject with a period

    line 95
  8. Distinctive:

    MUST use imperative mood in subject: the commit message completes the sentence *"If applied, this commit will..."*

    line 102
  9. Distinctive:

    MUST make each commit atomic — one logical change that compiles and passes tests independently

    line 103
  10. Distinctive:

    MUST NOT mix unrelated changes in a single commit (formatting + feature + bug fix)

    line 104
  11. Distinctive:

    SHOULD use Conventional Commits format for automated changelog and versioning

    line 105
  12. Distinctive:

    SHOULD include a body for non-trivial changes explaining WHY, not WHAT

    line 106
  13. Distinctive:

    SHOULD keep PRs under 200 lines of changed code

    line 123
  14. Distinctive:

    MUST include a clear description: context, what changed, why, how to test

    line 124
  15. Distinctive:

    SHOULD use PR templates to ensure consistent descriptions

    line 125
  16. Distinctive:

    MUST NOT submit PRs with failing CI checks

    line 126
  17. Distinctive:

    SHOULD separate refactoring from feature changes — refactoring PRs reviewed differently than feature PRs

    line 127
  18. Distinctive:

    When setting up or reviewing Git workflows, verify:

    line 204

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Git Best Practices

Reference: Pro Git (Chacon & Straub), Continuous Delivery (Humble & Farley), Accelerate (Forsgren et al.)

When to Apply

  • Choosing or evaluating a branching strategy for a team or project
  • Writing commit messages or reviewing them in pull requests
  • Structuring pull requests for effective code review
  • Setting up Git hooks and commit validation tooling
  • Implementing automated versioning and changelog generation
  • Improving DORA metrics (lead time, deployment frequency, change failure rate)

Branching Strategy

Trunk-Based Development (Recommended Default)

All developers collaborate on a single branch (trunk/main). Two variants:

VariantTeam SizeBranch LifetimeMerge Method
Direct to trunkSmall (≤5 developers)No branchesDirect push
Short-lived feature branchesAny size1–2 days maximumPR + merge
  • SHOULD default to trunk-based development — DORA research confirms higher-performing organizations are more likely to use TBD
  • MUST keep feature branches to 1–2 days maximum; MUST NOT let branches live longer than a week
  • MUST use feature flags to decouple deployment from release when features span multiple days

Branching Strategies Compared

StrategyBest ForAvoid When
Trunk-BasedSaaS, continuous deployment, high-cadence teamsN/A — suitable for most teams
GitHub FlowSimple — main + short-lived branches + PRsMultiple supported release versions
GitLab FlowTeams needing environment branches (staging, production)Teams doing continuous deployment
GitFlowVersioned software with multiple supported releasesContinuous delivery — Driessen himself (2020): "adopt a simpler workflow"

Feature Flags

Feature flags decouple deployment from release. MUST use them when incomplete features need to ship to production.

Flag TypePurposeLifetime
Release ToggleHide incomplete features in productionDays to weeks — remove after launch
Ops ToggleRuntime circuit breakers and operational controlsPermanent or long-lived
Experiment ToggleA/B testing and gradual rolloutDays to weeks — remove after decision
Permission ToggleFeature access by user segment (beta, premium)Long-lived
  • MUST remove release toggles promptly after the feature is fully launched
  • SHOULD track all active flags and assign cleanup owners

Commit Messages

Conventional Commits Format

<type>(scope): description

[optional body]

[optional footer(s)]

Core types and their SemVer mapping:

TypeSemVerPurpose
featMINORNew user-facing functionality
fixPATCHBug fix
feat! or BREAKING CHANGE: footerMAJORBreaking API change
docs—Documentation only
style—Formatting, whitespace (no logic change)
refactor—Code restructuring (no behavior change)
perfPATCHPerformance improvement
test—Adding or correcting tests
build—Build system or dependency changes
ci—CI configuration changes
chore—Other maintenance (no production code)
revert—Reverts a previous commit

Chris Beams' 7 Rules

  1. Separate subject from body with a blank line
  2. Limit subject to 50 characters
  3. Capitalize the subject line
  4. Do not end the subject with a period
  5. Use imperative mood — "Add feature" not "Added feature" or "Adds feature"
  6. Wrap body at 72 characters
  7. Body explains what and why, not how

Rules

  • MUST use imperative mood in subject: the commit message completes the sentence "If applied, this commit will..."
  • MUST make each commit atomic — one logical change that compiles and passes tests independently
  • MUST NOT mix unrelated changes in a single commit (formatting + feature + bug fix)
  • SHOULD use Conventional Commits format for automated changelog and versioning
  • SHOULD include a body for non-trivial changes explaining WHY, not WHAT

Pull Requests

Size Matters

PR SizeReview TimeDefect DetectionRecommendation
< 200 linesFast (~30 min)Highest (~40% more defects found)Ideal
200–400 linesModerateGoodAcceptable
400–1000 linesSlowDecliningSplit if possible
> 1000 linesVery slowDrops by ~70%MUST split

Rules

  • SHOULD keep PRs under 200 lines of changed code
  • MUST include a clear description: context, what changed, why, how to test
  • SHOULD use PR templates to ensure consistent descriptions
  • MUST NOT submit PRs with failing CI checks
  • SHOULD separate refactoring from feature changes — refactoring PRs reviewed differently than feature PRs

Stacked PRs

For features too large for a single small PR, use stacked PRs — a chain of small dependent PRs that build on each other.

  1. Break the feature into sequential, independently reviewable increments
  2. Each PR in the stack targets the previous PR's branch (or main for the first)
  3. Review and merge bottom-up
  4. Tools: Graphite, ghstack, git-branchless

Git Hooks

Client-Side Hooks

HookStagePurposeTooling
pre-commitBefore commit is createdLint, format, type-check staged fileslint-staged, prettier, eslint
commit-msgAfter message is enteredValidate conventional commit formatcommitlint
pre-pushBefore push to remoteRun tests, check for secretsjest, detect-secrets
prepare-commit-msgBefore editor opensPre-populate commit templatecommitizen

Hook Management Tools

ToolEcosystemKey Feature
HuskyNode.jsSimple setup with package.json scripts
pre-commitPython (language-agnostic)Large plugin ecosystem, runs hooks in isolation
LefthookGo binary (no runtime dependency)Parallel execution, fast, no Node required

Typical Hook Pipeline

pre-commit:
  1. lint-staged (format + lint only changed files)
  2. type-check (TypeScript, mypy)
  3. detect-secrets (prevent accidental credential commits)

commit-msg:
  1. commitlint (validate Conventional Commits format)

pre-push:
  1. test suite (unit tests, fast integration tests)

Automated Versioning and Release

Conventional Commits enable fully automated semantic versioning:

ToolApproachBest For
semantic-releaseFully automated: version, changelog, publish on mergeCI/CD pipelines with continuous release
release-please (Google)Creates and maintains release PRs; merge to releaseTeams wanting human approval before release; monorepo support
changesetsDevelopers describe changes; bot creates release PRMonorepos with multiple packages
commitizenInteractive CLI for crafting conventional commitsTeams onboarding to conventional commits

DORA Metrics Connection

The Accelerate research (Forsgren, Humble, Kim) shows four key metrics that distinguish high-performing teams:

MetricElite PerformanceConnection to Git Practices
Lead Time for Changes< 1 hourSmall PRs, trunk-based development, CI/CD
Deployment FrequencyMultiple per dayFeature flags, automated release
Change Failure Rate0–15%Atomic commits, comprehensive tests, small PRs
Time to Restore Service< 1 hourFast rollback via revert commits, feature flag kill switches

Checklist

When setting up or reviewing Git workflows, verify:

  • Branching strategy matches team size and deployment model (TBD preferred)
  • Feature branches live no longer than 1–2 days
  • Feature flags are used for incomplete features deployed to production
  • Commit messages follow Conventional Commits format with imperative mood
  • Each commit is atomic — one logical change, compiles, passes tests
  • PRs are under 200 lines; larger changes are stacked
  • PR descriptions include context, rationale, and testing instructions
  • Git hooks validate formatting, linting, and commit message format
  • Automated versioning is connected to Conventional Commits
  • Release toggles are tracked and removed after launch

Key References

BookAuthor(s)PublisherYear
Pro Git (2nd ed.)Scott Chacon, Ben StraubApress2014
Head First GitRaju GandhiO'Reilly2022
Continuous DeliveryJez Humble, David FarleyAddison-Wesley2010
The DevOps Handbook (2nd ed.)Kim, Humble, Debois, Willis, ForsgrenIT Revolution2021
AccelerateForsgren, Humble, KimIT Revolution2018
Software Engineering at GoogleWinters, Manshreck, WrightO'Reilly2020

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.