Before Git: CVS and Subversion
Version control predates Git by decades. RCS, the Revision Control System from the 1980s, tracked one file at a time on one machine. CVS, the Concurrent Versions System, wrapped RCS files into a shared, networked repository around 1990 and became the first open-source system that large projects used together.
CVS and its successor Subversion, first released in 2000, were centralized: one server held the history, and developers committed to it over the network. Subversion smoothed CVS’s rough edges with atomic commits and versioned directories and renames, but it kept the model. No server meant no commits and no history.
Distributed systems took the opposite shape. BitKeeper, released in 2000, gave every developer a complete copy of the project’s history. The Linux kernel adopted it in 2002, and its license collapse three years later set off a burst of distributed systems: Mercurial and Git were both started in April 2005.
Why the kernel needed a new system
From 2002 to 2005, the Linux kernel team used BitKeeper, a proprietary version control system. Its maker let open-source developers use it free of charge, with one restriction: no reverse engineering and no attempts to clone it.
In early 2005, an open-source developer in Australia did exactly that, and the maker revoked the kernel team’s free license. Kernel development lost the system that coordinated its contributors.
Linus Torvalds looked at the free alternatives and rejected them. CVS and Subversion were centralized, and he considered them too slow for the kernel’s pace and size. He spent about four months thinking through the design, starting in late 2004, and then wrote the replacement himself.
The goals stayed practical: apply a series of one hundred kernel patches in about half a minute, support thousands of parallel branches, work fully distributed, and stay fast with a repository the size of the kernel.
Ten days to a working system
Torvalds began typing code on April 3, 2005. By April 7 he had made the first commit: Git could record its own source. In about ten days it was usable enough for kernel work. The first version was roughly ten thousand lines and could be read in a single sitting.
The name was a joke. In British slang, a git is an unpleasant, contemptible person. Torvalds put it plainly: “I’m an egotistical bastard, and I name all my projects after myself. First ‘Linux’, now ‘Git’.”
He maintained the project for only about four months. In August 2005 he handed the role to Junio Hamano, citing Hamano’s taste as the main reason for the choice. Version 1.0 arrived that December, and Hamano has maintained Git ever since.
Plumbing and porcelain
The earliest documentation did not call Git a version control system. Torvalds described it as an information manager and a “stupid content tracker.” He wrote the low-level commands, the plumbing, and expected friendlier interfaces, the porcelain, to be built on top of them.
For the first week of kernel use, no porcelain existed. Torvalds committed by hand with raw plumbing commands: set the index, run commit-tree, take the hash it printed, and write that hash into the head file himself.
The first porcelain was a set of shell scripts he wrote around those commands, and even with those, Git was not easy to use. Modern Git keeps the split. Plumbing commands such as git hash-object, git cat-file, and git ls-tree move objects directly, while porcelain commands such as git add and git commit string the plumbing together for people.
Snapshots, not differences
CVS and Subversion record each change as a difference from the previous version. Git records each commit as a complete snapshot of the project.
Three kinds of object make this affordable. A blob holds one file’s contents. A tree holds a directory’s entries: each file’s name, permission bits, and the hash of its blob. A commit points to one tree, its parent commits, and the author and message.
A repository with one committed file shows the model directly. The commit named by the main branch points to its tree, and the tree lists the file’s blob:
$ git cat-file -p main
tree 54f86b561ea9f106a1592e66acb1975975e8c1bb
author Justin Jaramillo <[email protected]> 1792670400 +0000
committer Justin Jaramillo <[email protected]> 1792670400 +0000
First commit
$ git ls-tree 54f86b561ea9f106a1592e66acb1975975e8c1bb
100644 blob 43af0fe1f93c2aaf6786c4a6ab6df2a067e74fc2 readme.mdEach object’s hash is also its storage address. The first two characters name a directory under .git/objects, and the remaining characters name the file:
$ find .git/objects -type f
.git/objects/43/af0fe1f93c2aaf6786c4a6ab6df2a067e74fc2
.git/objects/54/f86b561ea9f106a1592e66acb1975975e8c1bb
.git/objects/15/4c5686dea14b4bca4f916ab4a5e985d2c5f21cSnapshots sound expensive, but content addressing deduplicates them. A file that has not changed hashes to the same value, so a new commit links back to the existing blob. The Linux kernel’s history holds more than 1.4 million commits across two decades and packs down to roughly 5.5 GB.
Hashes protect the history
The hashing was never about security. Torvalds wanted corruption detection: BitKeeper had protected some data with CRC checks and MD5 hashes but left parts unchecked, so he protected every object in Git with a strong hash from the start.
The protection works because an object’s name is the hash of its contents. If a disk error or a bad transfer changes one byte, the object no longer hashes to its own name, and git fsck reports the mismatch. Each commit also records the hash of its parent, so history forms a chain: quietly editing an old commit changes its hash and breaks every link after it.
Git also supports the newer SHA-256 hash for new repositories, though Torvalds has called that effort mostly pointless churn.
Branches, tags, and stashes are just files
A branch is not a copy of the project. It is a small file under .git/refs/heads that stores one commit hash:
$ cat .git/refs/heads/main
154c5686dea14b4bca4f916ab4a5e985d2c5f21cGit resolves the branch name to the commit above by reading that one file. HEAD points to the current branch, and each new commit records its parent, so history is a chain of hashes. Creating a branch writes a single file, which is why branching is nearly free.
A tag is the same idea holding still: a name for one commit, stored under .git/refs/tags. A lightweight tag is only a reference, while an annotated tag adds a small object with a tagger, a message, and an optional signature. Branch names must stay unique, but tag names only need a prefix to stay distinct, so filea-v1.0.0 and fileb-v1.0.0 can label different commits with the same version number.
The stash is built from the same machinery. Running git stash creates two hidden commits, one for the staged changes and one for the rest, and labels them with a reference called refs/stash. Not every reference is a branch or a tag.
Every clone is a full backup
A clone receives the complete history, not just the latest files. The design was deliberate: if a shared server fails or disappears, any developer’s copy can restore the whole project. Work happens locally, and exchanging changes is synchronization between equals.
Torvalds has said that this design is what made hosting services like GitHub, launched in 2008, almost trivial: every repository is the same and equal, so hosting one is mainly copying it. Those services carried Git from a kernel tool into everyday software work.
References
- Scott Chacon and Ben Straub: Pro Git — the creation story in chapter 1 and the object model in “Git Internals”
- Bruno Brito, Tower: Git Turns 20 — twenty facts from a conversation with Linus Torvalds
- Julia Evans: Some miscellaneous git facts — the stash and its commits
- Linus Torvalds: Git’s first commit — “Initial revision of ‘git’, the information manager,” April 7, 2005