Free preview · Beginner · 18 min read
Git Mental Model: Distributed History, Snapshots & Safe Experimentation
Build the mental model behind Git: snapshots, commits, refs, distributed repositories, immutable history and safe experimentation.
Free preview · Beginner · 18 min read
Build the mental model behind Git: snapshots, commits, refs, distributed repositories, immutable history and safe experimentation.
Git becomes much easier when you stop thinking of it as a cloud folder and start thinking of it as a local database of immutable snapshots connected by history.
A normal Git repository gives you three important things at once:
.git,Because Git is distributed, a clone normally contains enough history to inspect commits, create branches, compare versions and make new commits without talking to GitHub. Git is the version-control system. GitHub is a collaboration and hosting platform built around Git repositories.
A commit points to a project snapshot plus metadata such as author, committer, message and parent commit(s).
A --- B --- C --- D
^
main
main is not a folder. It is a movable reference that points to a commit. When you commit again, the branch reference moves forward.
Git objects are identified by content-derived object IDs. That gives Git a strong integrity model: changing a commit's content changes its identity and therefore the identities of descendants that refer to it.
You do not need to memorize Git internals on day one, but this explains why rewriting old history creates new commit IDs instead of editing an old commit in place.
A useful daily loop is:
inspect → edit → stage → review → commit → share
Commands:
git status
git diff
git add <path>
git diff --staged
git commit -m "Explain the change"
git push
The important engineering habit is the review step before commit and push. Git gives you multiple checkpoints where you can verify exactly what is changing.
| Concern | Git | GitHub |
|---|---|---|
| Local history | Yes | Hosts copies |
| Branching/merging | Yes | Adds PR workflow/UI |
| Commits/tags | Yes | Displays and governs them |
| Authentication | Transport-dependent | SSH/HTTPS/account controls |
| Code review | Basic diff tools | Pull requests/reviews/CODEOWNERS |
| Governance | Hooks/config | Rulesets/branch protection |
| Issues/projects | No | Yes |
Before running a destructive-looking command, ask:
The last question matters most. Rewriting your own unpublished branch is very different from rewriting a shared branch used by a team.