Git internals

Everything is just files

Within git, there’s no real magic going on - it’s all stored as files that you can explore in the .git directory. Interally, git utilises a simple key-value store, stored as objects.

The ref is the key, the object is the value.

You can directly manipulate git objects using the low-level git hash-object internal function

$ echo "secret thing" | git hash-object -w --stdin

and then recover it using git show

git show 7b90fa56ff6186a500b

secret thing

File storage in .git/objects/

You can directly inspect the files in their binary format, or blobs.

$ cat .git/objects/7b/90fa56ff6186a500b2aaac270d57fb4dc4c56a

The data here isn’t encrypted, it’s just in a format that needs decoding properly. To do that we can use the low-level object inspector git cat-file.

$ git cat-file -p 7b90fa56ff6186a500b2aaac270d57fb4dc4c56a
secret thing

File structure

  hooks/            < executable scripts for before/after git actions
  logs/             < stores links between refs
  objects/          < where the ref data is stored
    heads/          < local branch refs
      develop       < develop branch tip ref
      3.13.2        < tag ref
    stash           < stash ref
  COMMIT_EDITMSG    < most recent commit message
  config            < repo config settings
  HEAD              < stores the current HEAD ref
  index             < similar to git status
  packed-refs       < commonly accessed ref, branch tips, tags

Now we can touch on submodules