Conceptual Overview

Git was originally created in 2005 by Linus Torvalds as a system for managing changes to the Linux kernel. Although it is used for many of the same tasks as other version control systems like Subversion, Git’s internal workings are very different. It’s important to understand some of these concepts in order to use Git successfully.

Git maintains a repository; a directory structure that tracks the historical contents of a set of files. Generally, the repository is stored in a .git directory (or another directory named by $GIT_DIR) along with the files themselves.

Unlike other version control systems, Git does not enforce the concept of a “central repository.” Instead, every set of files tracked by Git has its own .git repository, and revisions can be easily pushed and pulled from one repository to another.

The set of files currently being tracked by Git is called the working tree. The working tree is where most of your daily work takes place. By default, the working tree starts in the parent directory of the .git directory. (You can override this by setting $GIT_WORK_TREE.) The operation of creating a working tree from a repository is called checking out the files, which is done by git checkout. After modifying the files in the working tree, you save the changes back to the repository by committing them with git commit (this is also called checking in).

Unlike other systems, Git introduces an extra, intermediate state between the repository and the working tree called ...

Get Linux in a Nutshell, 6th 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.