lab 22 Git Internals:
The .git directory

Goals

The .git Directory 01

Time to do some exploring. First, from the root of your project directory…

Execute:

ls -C .git

Output:

$ ls -C .git
COMMIT_EDITMSG	branches	hooks		logs
HEAD		config		index		objects
ORIG_HEAD	description	info		refs

This is the magic directory where all the git “stuff” is stored. Let’s peek in the objects directory.

The Object Store 02

Execute:

ls -C .git/objects

Output:

$ ls -C .git/objects
11	16	27	43	59	69	78	af	d7	info
12	1f	28	44	5d	6b	97	b3	dc	pack
14	24	2a	4f	5e	6c	9c	c6	e6

You should see a bunch of directories with 2 letter names. The directory names are the first two letters of the sha1 hash of the object stored in git.

Deeper into the Object Store 03

Execute:

ls -C .git/objects/<dir>

Output:

$ ls -C .git/objects/11
b345c2fc315b5f7ae6db2e0f6b0570780c20d1

Look in one of the two-letter directories. You should see some files with 38-character names. These are the files that contain the objects stored in git. These files are compressed and encoded, so looking at their contents directly won’t be very helpful, but we will take a closer look in a bit.

Config File 04

Execute:

cat .git/config

Output:

$ cat .git/config
[core]
	repositoryformatversion = 0
	filemode = true
	bare = false
	logallrefupdates = true
	ignorecase = true
	precomposeunicode = false
[user]
	name = Ismail Dhorat
	email = ismail@codiez.co.za

This is a project-specific configuration file. Config entries in here will override the config entries in the .gitconfig file in your home directory, at least for this project.

Branches and Tags 05

Execute:

ls .git/refs
ls .git/refs/heads
ls .git/refs/tags
cat .git/refs/tags/v1

Output:

$ ls .git/refs
heads
tags
$ ls .git/refs/heads
master
$ ls .git/refs/tags
v1
v1-beta
$ cat .git/refs/tags/v1
dc44f2e4c830403ed7da3988e94dd1d97160c7b4

You should recognize the files in the tags subdirectory. Each file corresponds to a tag you created with the git tag command earlier. Its content is just the hash of the commit tied to the tag.

The heads directory is similar, but is used for branches rather than tags. We only have one branch at the moment, so all you will see is master in this directory.

The HEAD File 06

Execute:

cat .git/HEAD

Output:

$ cat .git/HEAD
ref: refs/heads/master

The HEAD file contains a reference to the current branch. It should be a reference to master at this point.

Table of Contents