Part II. Fundamentals of Git

The following chapters highlight how Git manages files, explain the importance of the index and how it relates to this process, and take a detailed look at the commit object and the important role that branches play in a Git repository.

Before we proceed, we would like to explain why we chose to discuss these topics in this order.

In “Git Internals: Concepts at Work”, we dissected the available objects within the Git object store. Let’s look at how the objects are created and when they establish links with each other.

First we will create an empty directory and inspect the content using the tree command:

   $ mkdir myrepo && cd myrepo

   $ git status
   fatal: not a git repository (or any of the parent directories): .git

   $ tree .git
   .git [error opening dir]

   0 directories, 0 files
   

Since this is not a Git repository, there is no .git directory. Next, we will initialize an empty Git repository and reinspect the directory content:

   $ git init -b main
   Initialized empty Git repository in /myrepo/.git/

   $ tree .git .git ├── HEAD ├── config ├── description ├── hooks │ ├── applypatch-msg.sample │ ├── commit-msg.sample │ ├── fsmonitor-watchman.sample │ ├── post-update.sample │ ├── pre-applypatch.sample │ ├── pre-commit.sample │ ├── pre-merge-commit.sample │ ├── pre-push.sample │ ├── pre-rebase.sample │ ├── pre-receive.sample │ ├── prepare-commit-msg.sample ...

Get Version Control with Git, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.