Git: the object model and workflows
Git as a content-addressed store of blobs, trees and commits on a real repository; refs, HEAD and the index; the commit graph, three-way merge and rebase; undoing; remotes as object transfer; branching workflows, review and protected branches.
Objects: blobs, trees and commits
Every build in the rest of this course starts from an exact version of source files. Git keeps that history as a small regular data structure: a store of immutable objects named by their hashes, linked into a graph, with movable names pointing into it.
Under .git/objects the value is an object; the key is a hash of its type, size and content. Three kinds matter:
- a blob — the bytes of one file, with no name and no permissions;
- a tree — one directory: mode, type, hash and name per entry;
- a commit — hash of a root tree, zero or more parent commits, author, committer, timestamps and a message.
Worked example. After git add of README.md (Shop service\n, 13 bytes) and src/app.py, two blobs exist. The README name is the SHA-1 of blob 13\0 plus the content — the same digest shasum computes. A commit writes trees and a commit object. A second commit that changes only app.py adds one blob, two trees and one commit; the README blob is shared. git count-objects reports 9 objects.
Refs, HEAD and the index
A ref is a file holding a hash: branch main is .git/refs/heads/main. HEAD normally holds the name of a branch (a symbolic ref). A commit writes a tree from the index, writes a commit whose parent is where HEAD resolves, and moves that branch. Creating a branch writes about 41 bytes.
Every file has three versions to compare:
| Where | Holds | Compared by |
|---|---|---|
| working tree | files on disk | git diff |
| index | next commit's snapshot | git diff --staged |
| HEAD | last commit | git diff HEAD |
When HEAD holds a raw hash, the repository is in detached HEAD: new commits exist but no branch moves.
Key idea and consequences
Key idea. Git is a content-addressed store: every object is named by the hash of its content, and objects refer to each other by those names. A commit names a tree and its parents, so its hash covers the entire snapshot and the entire history behind it. Objects never change; everything that looks like a change — new commit, merge, rebase, reset — adds objects or moves a name.
Three consequences the course relies on: deduplication, integrity (a Merkle tree: change a byte and every ancestor hash changes), immutability. A build that records the commit hash it was made from is reproducible from that hash alone.
SHA-1 is still the default (October 2026) with collision detection (SHA-1DC) since Git 2.13; SHA-256 repositories are non-experimental since 2.42; Git 3.0 plans SHA-256 as the default for new repositories when the ecosystem is ready.
Merge and rebase
Parallel work meets in the commit graph. A three-way merge compares our tip, their tip and the merge-base (common ancestor). Same-side edits land cleanly; same-line edits conflict in the working tree and index stages.
Rebase copies a sequence of commits onto a new base as new objects (new hashes), yielding a linear history. Merge adds one commit with two parents and preserves the branching shape. Rebase of commits already pushed to a shared branch rewrites public history — coordinate or avoid. git revert adds a new commit that undoes a change without rewriting; reset moves a ref (and can discard commits that nothing else names).
Remotes and workflows
A remote is another object store plus refs. fetch and push transfer missing objects and update refs; agreeing on a commit hash means agreeing on all reachable history.
Common workflows:
| Trunk-based | GitHub flow | Git flow | |
|---|---|---|---|
| Long-lived branches | main only |
main only |
master and develop |
| Branch lifetime | hours | hours to days | days to weeks |
| Unfinished work | feature flags | on its branch | on its branch |
| Fits | continuous delivery | CD with review | parallel versioned releases |
Protected branches and required reviews encode the feedback way: nothing reaches main untested and unseen.
What changed
| Copies of files | Centralized VCS | Git | |
|---|---|---|---|
| Unit of history | a copied folder | server revision | commit snapshot by hash |
| Offline | yes, without history | no | yes, full history |
| Branch | copied folder | server-side copy | ~41-byte ref |
| Integrity | none | the server's | every hash covers history below |
Commands stop looking arbitrary once they are operations on the graph. The next topic, Builds and dependencies, starts from a commit hash and asks how source becomes a reproducible artifact.
Check your understanding
The same questions as in Pulse. Answers are shared between modes.
Go deeper — optional
Code and labs do not count toward the main percentage or the certificate.
- Object model: blob/tree/commitoptional
From hashes rebuild commit→tree→blobs; explain why a rename is delete+add of content.
~20 min · easier on a computer · The matching course topic has been read.
Self-check in the notebook — not part of mastery or the certificate.
Answers are saved on the server and tied to this browser until you sign in.