2.1 Git Repository

When we use git init, Git will create a repository in a .git directory within the current working directory which become the Git workspace. You edit your files in the workspace just as you normally would and use git commands to manipulate objects and data stored in the .git database (known commonly as the repository).

1mkdir class 
2cd class 
3ls -a 
4git init 
5tree -a

Within the .git directory are a number of files and sub-directories that constitute the .git database.

tree -a
1.git 
2├── branches 
3├── config 
4├── description 
5├── HEAD 
6├── hooks 
7   ├── applypatch-msg.sample 
8   ├── commit-msg.sample 
9   ├── fsmonitor-watchman.sample 
10   ├── post-update.sample 
11   ├── pre-applypatch.sample 
12   ├── pre-commit.sample 
13   ├── prepare-commit-msg.sample 
14   ├── pre-push.sample 
15   ├── pre-rebase.sample 
16   ├── pre-receive.sample 
17   └── update.sample 
18├── info 
19   └── exclude 
20├── objects 
21   ├── info 
22   └── pack 
23└── refs 
24    ├── heads 
25    └── tags 
26 
279 directories, 15 files

A few are of less interest to us at the moment:

  • config—holds configuration to be used on this repository (more on git configuration later)
  • description—used to provide a description of this repository to the web interface (not something we will look at for a while)
  • info—contains the files to be ignored (.gitignore, to be investigated later) for this project’s workspace.
  • hooks—these are small scripts that can be triggered on certain actions. We will use these later but for now they can be ignored. These take up a lot of room on our output, we don’t need these, so let’s delete them (I’ll leave the directory, even though it is not required, to remind us that it’s typically there).
    1rm .git/hooks/*

The ones we are most interested in this chapter are:

  • HEAD—Holds a special reference to the last object stored from the workspace
  • objects—this holds the data
  • refs—this holds references into the data in objects

We will see several other files and directories created as we use Git and we will discuss these as they occur.

There are several types of object held in .git repositories, the three we will encounter in this chapter are:

  1. blobs—containing the data we want to store (typically files)
  2. trees—containing data about sets of blobs (and other trees)
  3. commits—containing metadata about trees

No need to worry about the details, all will become clear as we progress through this chapter.