What is Git made of? (2022)

https://lobste.rs/rss Hits: 26
Summary

What is Git made of?Git can be confusing. Git can be scary. Git CLI may be the least intuitive tool you have to use on a daily basis.But also Git is a wonderfully simple and cleverly designed version control system that definitely deserves its popularity.To prove this point I invite you to implement your own tiny Git that would be able to create a local repository, commit a single file to it, view commit logs and checkout a certain revision of that file.It won’t be more than a couple hundred lines of code, we’ll try to keep things as simple as we can. Code examples would be in Go, but any other language is suitable for this tutorial, too.git initWhat turns an empty directory into an empty Git repository? You probably have noticed that Git stores all its internal data in a hidden directory .git. In fact, there are only a few special files/folder there that have to be created to let Git CLI treat it as a perfectly valid, empty repository:$ mkdir -p .git/objects/info .git/objects/pack .git/refs/heads .git/refs/tags $ echo "ref: refs/heads/main" > .git/HEAD $ tree .git .git ├── HEAD ├── objects │ ├── info │ └── pack └── refs ├── heads └── tags $ git symbolic-ref --short HEAD main $ git log fatal: your current branch 'main' does not have any commits yet By using a couple of shell commands we’ve tricked Git into recognising our empty repository with a single main branch and no commits. But what is stored in these directories we’ve created?objectsAlmost everything in Git is stored as an object: every source file that you commit becomes a blob object, every commit itself is an object, tags are objects, too.For example, we have committed a file.txt with the contents hello\n (6 bytes). This would create 3 objects: a blob (actual file contents), a tree (a list of file names and permissions), and a commit (a reference to the committed tree with some information about the committer, timestamp etc).For every object Git stores its object type (“blob”, “tree” or “commit”) and a len...

First seen: 2026-05-24 03:47

Last seen: 2026-05-25 05:06