Git & GitHub·Under the hood

How Git stores history

Read objects, refs and HEAD to understand why recovery works.

Beginner 12 min read Lesson 15 of 480 Challenge included
What you will be able to do
  • Inspect commit objects
  • Explain what a branch points to
  • Use the object graph to diagnose a problem

Git stores content in immutable objects: blobs for files, trees for folders and commits for snapshots. Branches are just pointers to commits, and HEAD points to the branch you are on.

internals.shTerminal
git rev-parse HEAD
git cat-file -t HEAD
git cat-file -p HEAD
git ls-tree HEAD
git show --stat HEAD
ObjectStores
blobFile contents
treeA directory: names, modes and object IDs
commitA snapshot, parent, author and message
tagAn annotated pointer to an object
Your turn

Inspect the current commit

Medium

Show the type and contents of the current HEAD object, then list its tree.

BASH · starter
# your commands here
Check your understanding before moving on.
Knowledge checkQuestion 1

What does a branch point to?

Select an answer to continue
Study tools

Make it yours.

Keep a private note for this lesson, then turn the key ideas into flashcards you can revisit.

Sign in to save notes and flashcards.Both are private to your account and stay with your progress.
Sign in
Finished reading?

Lock in what you just learned.

Mark this lesson complete to save your place and move one step closer to the certificate.

Next: Project: ship a change
Lesson 15 of 480 · 0% of course