Git & Version Control
Master Git branching, merging, rebasing, conflict resolution, and GitHub workflows - the foundation of collaborative software development.
skill: Git & Version Control category: Developer Experience tags: [Git, GitHub, Version Control, Branching, Collaboration] readingTime: 6
Git mastery multiplies every other engineering skill - it's the foundation of collaboration, code review, and deployment. Most developers use only 10% of Git's capabilities and work around the rest. Understanding rebase, cherry-pick, bisect, and reflog turns frustrating situations into 5-minute fixes.
Workflow
- Use a clear branching strategyWithout a branching convention, feature branches pile up and merging becomes a nightmare. A clear strategy makes the deployment pipeline predictable.
- Write meaningful commit messagesGood commit messages make git log a timeline of decisions - not just a list of changes. Conventional Commits format enables automatic changelogs.
- Rebase for a clean historyMerge commits from feature branches create a cluttered, hard-to-read history. Rebase rewrites commits on top of the target branch - linear and clean.
- Use git bisect, cherry-pick, and stashThese three commands solve the most common 'I'm stuck' Git situations without brute force.
- Recover from mistakes with reflogGit reflog records every HEAD movement - including commits that are 'deleted' by reset or rebase. Almost any mistake is recoverable within 30 days.
Output Format
Git workflow: conventional commits, GitHub Flow branching, interactive rebase, and recovery with reflog.
.commitlintrc.json: { 'extends': ['@commitlint/config-conventional'] }
.husky/commit-msg: npx --no-install commitlint --edit $1
Branch: feature/scope-description
Commit: type(scope): subject (< 72 chars)
PR: squash-and-merge to keep history cleanExamples
Input
Output
Edge Cases & Gotchas
- Force push to shared branches - git push --force overwrites the remote, losing other people's commits. Use --force-with-lease instead - it only force-pushes if you have the latest remote state.
- Merge conflicts in binary files - Git can't auto-merge binary files (images, fonts, compiled artifacts). Use git checkout --ours or --theirs to pick one version completely.
- Large files slowing clone - Large binary files committed to git bloat the repo for all time. Use git-lfs (Large File Storage) for assets, or .gitignore to exclude build artifacts.
- Detached HEAD state - Checking out a commit directly puts you in detached HEAD - commits made here are abandoned when you switch branches. git checkout -b my-branch to save the work.
When to Break These Rules
- Use a GUI Git client (Fork, Tower, GitKraken) for complex merge conflict resolution - visual diff is significantly easier than CLI for multi-file conflicts.
- Use Sapling (Meta's VCS) or Jujutsu for experimental workflows that need better support for mutation and alternative history models - standard Git for all production use.
Reference Files
https://git-scm.com/book/en/v2https://www.conventionalcommits.org/