Git and GitHub · Part 4 · Team workflows

Part 4 summary: Team workflows

The big idea

A team agrees how to branch, writes commit messages in one format, and lets hooks check the small things automatically. When something goes wrong anyway, the first question is whether it was pushed: unpushed history can be rewritten, pushed history gets a new commit that fixes it.

Each lesson in one line

  1. Branching strategies: GitHub Flow for most teams, Git Flow for versioned releases, trunk-based for teams that deploy constantly.
  2. Conventional commits: type(scope): description, so people and tools can read the history.
  3. Git hooks: scripts that run before a commit or push; Husky shares them with the team.
  4. Handling real-world mess: the reflog finds lost commits, revert undoes pushed ones, and a leaked key is revoked first.

Key terms

TermMeaning
Branching strategyA team's agreed plan for which branches exist and how work flows between them
GitHub FlowShort branches off main, merged by pull request; main is always deployable
Git Flowmain for releases, develop for the next one, plus feature, release and hotfix branches
Trunk-based developmentEveryone merges into main at least daily, with very short branches
Feature flagAn on/off switch that hides unfinished code in production
Conventional CommitsA message format: type, optional scope, description
Breaking changeA change that breaks existing users, marked with ! or BREAKING CHANGE:
Git hookA script Git runs automatically at a set moment, such as before a commit
HuskyA tool that keeps hooks in a committed folder, so the whole team has them
lint-stagedRuns formatters and linters on staged files only
commitlintChecks commit messages against a format
ReflogThe local diary of every place HEAD has been
HEAD@{1}Where HEAD was one step ago
RevertA new commit that undoes an earlier one, safe for pushed history
Push protectionA GitHub feature that blocks pushes containing known kinds of secrets

Essential commands

CommandWhat it does
git commit -m "feat(cart): add promo codes"A commit in Conventional Commits format
npx husky initSets up shared hooks
npx lint-stagedChecks staged files (in .husky/pre-commit)
git commit --no-verifySkips hooks once
git reflogShows where HEAD has been
git reset --hard HEAD@{1}Goes back to where HEAD was before the last step
git branch name hashRecreates a deleted branch
git revert hashUndoes a pushed commit
git revert -m 1 hashUndoes a pushed merge
git rm --cached .envStops tracking a file without deleting it

Rules to remember

  • Write the team's rules down, often in CONTRIBUTING.md, and follow them over personal habits.
  • Describe the change, not the effort. fix(cart): keep the total, not “fixed stuff”.
  • Keep hooks fast, and run the same checks again on GitHub, since hooks can be skipped.
  • Before fixing a mistake, ask: was it pushed? Rewrite only what's local; revert what's shared.
  • Check the reflog before panicking. Committed work is almost never really lost.
  • A leaked secret is revoked first, then removed.