How git works – Onion View – Persistent structure

« Porcelain » commands

« Plumbing » commands – scripting

If you want to master git, you don’t need to worry about learning the commands. Instead, learn the concept model.

Git can be seen like an onion.

A simple persistent structure that maps keys to values (the structure is persistent, it’s stored on your disk) – the basic idea behind git: a map.

values = sequences of bytes (the content of a text value)

keys = git will calculate keys for these values using SHA1 (hash)

Every object (text files, directories, commits) in Git has its own SHA1. It is unlikely they will collide, they are unique.

Inside the .git directory, there is an object directory where Git saves all its objects.

git hash-object

git cat-file to see the content of the file (the original content was compressed to save space and added some more stuff).