π Handbook Home Β Β·Β β¬ οΈ Prev: Actions, Pages & Releases Β Β·Β Next: Troubleshooting β‘οΈ
Knowing the commands is one thing; using them like a pro is another. This chapter is the "good habits" guide that separates tidy, collaborative repos from chaotic ones.
A commit message explains why a change happened β your future teammates (and future you) will thank you.
The 7 rules of a great commit message:
- Separate subject from body with a blank line.
- Limit the subject to ~50 characters.
- Use the imperative mood: "Add login", not "Added login" or "Adds login".
- Capitalize the subject; no period at the end.
- Use the body to explain what and why (not how).
- Wrap the body at ~72 characters.
- Reference issues:
Closes #128.
Add rate limiting to the login endpoint
Brute-force attempts were possible because there was no throttle.
Limit to 5 attempts per IP per minute, returning HTTP 429 after that.
Closes #142
A popular, machine-readable convention β great because it can auto-generate changelogs and version bumps:
<type>(optional scope): <description>
feat: a new feature fix: a bug fix
docs: documentation only refactor: code change, no behavior change
test: adding/fixing tests chore: tooling, deps, config
perf: a performance improvement style: formatting only
Examples: feat(auth): add password reset, fix: handle empty cart, docs: clarify install steps.
One logical change per commit. Don't mix a bug fix, a refactor, and a typo correction into one commit. Atomic commits are easier to review, revert, and cherry-pick. Use git add -p to split work into clean pieces.
Consistent names keep a busy repo readable:
feature/search-bar feat/ β new work
fix/login-crash bug/ β bug fixes
hotfix/payment-timeout hotfix/β urgent production fixes
chore/upgrade-deps chore/ β maintenance
docs/api-guide docs/ β documentation
Some teams add issue numbers: feature/142-search-bar.
How a team organizes branches. Pick one and be consistent.
main ββββββββββββββββββββββ (always deployable)
β² β± β² β±
βββ βββ (short-lived feature branches β PR β merge)
- One long-lived branch:
main(always shippable). - Every change is a short-lived branch β PR β review β merge β deploy.
- β Best for web apps & continuous deployment. Recommended default for most teams.
main ββββββββββββββββββββββ (production; tagged releases)
release ββββββββββββββββββ
develop βββββββββββββββββββββββ (integration branch)
feature βββββββββββββββββββββββ (off develop)
- Multiple long-lived branches:
main,develop, plusfeature/*,release/*,hotfix/*. - β
Good for versioned software with scheduled releases;
β οΈ heavier, often overkill for web apps.
main ββββββββββββββββ everyone commits to main (behind feature flags)
- Everyone integrates into
mainmany times a day; very short branches. - β Enables true continuous delivery at scale; relies heavily on automated tests & feature flags.
| Model | Long-lived branches | Best for |
|---|---|---|
| GitHub Flow | main only |
Most teams, web apps, CD |
| Git Flow | main + develop |
Scheduled, versioned releases |
| Trunk-Based | main only |
High-velocity teams with strong CI |
- Ignore dependencies (
node_modules/), build output (dist/), secrets (.env), and OS/editor junk (.DS_Store,.idea/). - Start from a template: github.com/github/gitignore has one for every language.
- Already committed something you shouldn't have?
git rm --cached <file>, then ignore it.
API keys, passwords, and tokens do not belong in Git β once pushed, assume they're compromised forever (history is public/clonable).
- Keep secrets in
.envfiles (git-ignored) or a secrets manager. - Use GitHub Secrets for CI (Chapter 14).
- Enable Secret Scanning & push protection (Settings β Security).
- Leaked one? Rotate the key immediately, then scrub history with
git filter-repoor the BFG Repo-Cleaner. (See Troubleshooting.)
- Small PRs get reviewed faster and better than giant ones.
- Write a clear description; link the issue (
Closes #X). - Respond to every review comment; resolve threads as you go.
- As a reviewer: be kind, specific, and timely; use
suggestionblocks; approve when it's good enough, not perfect.
- Write imperative, focused commit messages; consider Conventional Commits.
- Keep commits atomic β one logical change each.
- Use consistent branch names and a clear branching model (GitHub Flow suits most teams).
- Be disciplined with
.gitignoreand never commit secrets. - Keep PRs small and reviews kind.
π Handbook Home Β Β·Β β¬ οΈ Prev: Actions, Pages & Releases Β Β·Β Next: 16 Β· Troubleshooting β‘οΈ