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
- Branching strategies: GitHub Flow for most teams, Git Flow for versioned releases, trunk-based for teams that deploy constantly.
- Conventional commits:
type(scope): description, so people and tools can read the history. - Git hooks: scripts that run before a commit or push; Husky shares them with the team.
- Handling real-world mess: the reflog finds lost commits, revert undoes pushed ones, and a leaked key is revoked first.
Key terms
| Term | Meaning |
|---|---|
| Branching strategy | A team's agreed plan for which branches exist and how work flows between them |
| GitHub Flow | Short branches off main, merged by pull request; main is always deployable |
| Git Flow | main for releases, develop for the next one, plus feature, release and hotfix branches |
| Trunk-based development | Everyone merges into main at least daily, with very short branches |
| Feature flag | An on/off switch that hides unfinished code in production |
| Conventional Commits | A message format: type, optional scope, description |
| Breaking change | A change that breaks existing users, marked with ! or BREAKING CHANGE: |
| Git hook | A script Git runs automatically at a set moment, such as before a commit |
| Husky | A tool that keeps hooks in a committed folder, so the whole team has them |
| lint-staged | Runs formatters and linters on staged files only |
| commitlint | Checks commit messages against a format |
| Reflog | The local diary of every place HEAD has been |
HEAD@{1} | Where HEAD was one step ago |
| Revert | A new commit that undoes an earlier one, safe for pushed history |
| Push protection | A GitHub feature that blocks pushes containing known kinds of secrets |
Essential commands
| Command | What it does |
|---|---|
git commit -m "feat(cart): add promo codes" | A commit in Conventional Commits format |
npx husky init | Sets up shared hooks |
npx lint-staged | Checks staged files (in .husky/pre-commit) |
git commit --no-verify | Skips hooks once |
git reflog | Shows where HEAD has been |
git reset --hard HEAD@{1} | Goes back to where HEAD was before the last step |
git branch name hash | Recreates a deleted branch |
git revert hash | Undoes a pushed commit |
git revert -m 1 hash | Undoes a pushed merge |
git rm --cached .env | Stops 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.