Cross-Cutting Tools Deep Dive · 1 of 6

Git — Distributed Version Control

Linus Torvalds wrote Git in 2005 to host the Linux kernel after the BitKeeper fallout. Twenty years later it is the version control system. Subversion still ships in places, Mercurial has loyalists, but for almost every new project the question isn't which VCS — it's which Git host.

DistributedSnapshotsBranchesSHA-1DAG
← Back to Cross-Cutting Tools
Mental Model

What Git Actually Stores

Basic Concepts

  • Snapshots, not diffs. Every commit is a full snapshot of the working tree, hashed and stored as an object. Git computes diffs on demand.
  • Content-addressed objects. Blobs (file contents), trees (directories), commits (snapshot + parent + author + message), tags. Identified by SHA-1 of their content.
  • Branches are pointers. A branch is a 40-character file pointing at one commit. Cheap to make, cheap to throw away.
  • Three areas: working tree (your files), index/staging (what the next commit will contain), repository (the committed history under .git/).
  • Distributed. Every clone is a full repository with full history. There is no privileged server in the protocol — only by convention.
The Commands That Matter

What You'll Run Daily

CommandWhat it does
git cloneCopy a remote repository, full history included.
git status / diffWhat's changed, what's staged.
git add / commitStage files, then snapshot them with a message.
git switch / checkoutMove between branches.
git pull / fetch / pushSync with a remote. fetch is read-only; pull is fetch + merge.
git merge vs rebaseBoth integrate work. Merge preserves history; rebase rewrites it onto a new base.
git log / blame / bisectRead history, find who changed a line, binary-search a regression.
git stashSet aside uncommitted work to switch contexts.
git reflogYour safety net — every HEAD movement is logged for ~90 days, even after "destructive" commands.
Workflows

How Teams Actually Use It

Trunk-Based Development

Everyone commits to a single long-lived branch (main) at least daily. Short-lived feature branches that merge within a day or two. Releases are tags or release branches cut from trunk. This is what most modern high-velocity teams do — it forces small PRs, fast review, and feature flags for unfinished work. CI keeps trunk green.

GitFlow

Long-lived develop and main, plus feature, release, and hotfix branches. Designed for shipping versioned software with parallel maintenance. Heavy for SaaS where you ship continuously; still useful for libraries, mobile apps with app-store cycles, and embedded firmware.

GitHub Flow / Pull Request Workflow

Branch off main, push, open a pull request, get review, merge. The "default" workflow on GitHub/GitLab/Bitbucket. Pairs naturally with trunk-based development when branches are short-lived.

Forking Workflow

Each contributor has their own copy of the repo (a fork) and submits PRs upstream. The standard for open-source — the maintainer doesn't have to grant write access to every drive-by contributor.

The Sharp Edges

Where People Get Hurt

  • Force push to a shared branch. git push --force rewrites the remote — anyone who'd pulled the old commits has to recover. Use --force-with-lease, and never force-push main.
  • Rebasing public history. Rebase your local feature branch all you want; rebasing something others have based work on creates two divergent histories.
  • Merge conflicts in generated files. Lockfiles, snapshots, generated bundles — set a merge driver or regenerate after merge instead of hand-resolving.
  • Committed secrets. Once a credential is in history, it's effectively public. Rotate the secret, then rewrite history with git filter-repo if needed. Pre-commit hooks (gitleaks, trufflehog) catch them earlier.
  • Large binaries. Git is optimized for text. Binaries bloat the repo forever. Use Git LFS for assets, or keep them out of the repo entirely.
  • Detached HEAD. Not actually scary — you're just on a commit, not a branch. Make a branch (git switch -c) before committing if you want the work to be findable.
Continue

Other Cross-Cutting Tools