Demystifying Git: Four Areas of Git

Sai Charan Adurthi
3 min readMay 21, 2019

--

This article is a part of a series of articles on Git.

In the previous article “Introduction to Git”, I have discussed

  • what is VCS
  • What is Git
  • Why is Git used in software development
  • Pointers to install Git and get started with Git.

Now, in Demystifying Git I will explain how Git, a git command work under the hood.

To understand how any git command works on a given repository.

We need to understand the following two concepts:

  1. The four areas of git
  2. The basic workflow in the four areas of git

The four areas of git :

A git project stores information in four separate storage areas.

The following areas are created when we run “git init” command

The Four Areas of Git

The Working Directory :

It is the project directory on your local file system (i.e. any folder or project upon which you initialize git)

It is the place where we keep all our files and folders of project/repository.

The Repository :

It is present inside the “.git” folder of the project/repository. The main data is present inside a folder called “objects” inside this “.git” folder.

Objects folder has three types of objects:

  1. Blobs — this type of object represents the content of a file at some point in history.
  2. Trees — this type of object represents a folder containing files.
  3. Commits — this type of object represents a commit in history.

All the above three objects are immutable i.e. they can only be created or deleted but cannot be modified once created.

These above objects are linked together in a structure to represent the history of a project.

Each commit points to a graph of trees (that represent folders) and blobs (that represent files) in the project at the point/commit in history.

Objects inside a git repository

Also, two commits can share the same objects. Example, in the above image you can see that commit 1 and commit 2 share, tree 3, blob 2 and blob 3 objects. And that’s the way git stores changes to files and directories.

commits in git

Each commit points to a parent commit in the history.

Remember, each commit is like a snapshot of commits in history i.e. freeze frame of project history.

If we refer to a commit in the history then we refer to all of its parent commits indirectly.

Example, here in the image if we refer to commit 7, then we refer to commits 6, 2, 3 and 1 indirectly.

What is a branch?

A branch is a reference to a commit object in the tree.

What is a HEAD in Git?

A “HEAD” is a reference that always points to the current branch in the repository tree. Thereby, indirectly pointing to current commit.

branches in git

Unreachable Commits — Are those commits that cannot be reached from any commit in the repository tree.

The Index :

The index is very specific to git. Because almost all VCS(version control systems) have a working directory and a repository. But, only Git has an Index or at least it allows us to use the Index.

Index can be thought of as an intermediate area between the working directory and repository. Changes made in the working directory cannot be directly sent to the repository.

Index is used to add changes and then commit them to the repository. Hence, index is also called the “staging area”.

The basic workflow for a command in all the four areas of Git will be discussed in the next article “Demystifying Git: Basic workflow in the four areas”.

--

--

Sai Charan Adurthi

Tech Head | Fitness Freak 🏋| Gallivanter✈️🏕| #charanthecsguy