slides url:

Git: Under The Hood

Host: OpenUTD

Speaker: C. Michael Murphey



ref is short for reference

A ref is kind of like an alias for a commit

Just like anything else in Linux, a ref is actually a file

You can find each ref in the .git directory


a branch is actually just a ref

a tag is actually just a ref


Many of you have probably interacted with HEAD

HEAD is actually just a (special) ref!

Wait. What's a tag?

It's basically just a fancy alias for a commit

Project maintainers often tag the last commit of a version

git tag v1.0.1

Wait. What's HEAD?

It's basically just a fancy alias for the most recent commit

git reset HEAD will reset back to the most recent commit

refs: opening the hood

You can look at what a ref is pointing to with git rev-parse insert-ref-here

You can look at what's in that commit with git show insert-ref-here

refs: opening the hood

Since refs are just plain text files, you can read them with a text editor

You may see

  • refs: path/to/other/ref
  • A commit hash

refs: sticking your hand in the engine

You can manually modify and create refs by editing files in .git/

Don't do this in any repos you actually care about

So, how is git actually storing the changes?

Git objects!

Types of git objects

  • Commit objects

  • Tree objects

  • Blob objects

Commit objects

This contains the metadata of the commit and points to a tree object

Tree objects

Trees can have other trees and/or blobs as children. They represent directories.

Blob objects

These contain the (compressed) contents of a file being tracked

Here's what the object graph looks like

Here's the big picture

Let's look for ourselves ourselves

OK, now for some useful tips


The reflog keeps track of almost everything you do with refs

You can see the history with git reflog

You can go back in time by checking out objects and refs from the reflog

Garbage Collection

Git's garbage collector helps conserve disk space

The garbage collector which will remove unused objects, prune the reflog and move refs into the file .git/packed-refs

Garbage Collection

Many of git's commands will automatically invoke the garbage collector

The garbage collector can be run manually with git gc

Warning: now there's actually no going back

To sum it all up

refs can point to other refs or commit objects

commit objects can point to other commit objects and trees

tree objects can point to other trees or blobs

blob objects contain the contents of the files in the git repository


More References

Thank You