There are three main components of a Git project:

  • Repository
  • Working tree
  • Index

The repository, or repo, is the “container” that tracks the changes to your project files. It holds all of the commits — a snapshot of all your files at a point in time — that have been made. You can access the commit history with the Git log.

The working tree, or working directory, consists of files that you are currently working on. You can think of a working tree as a file system where you can view and modify files.

The index, or staging area, is where commits are prepared. The index compares the files in the working tree to the files in the repo. When you make a change in the working tree, the index marks the file as modified before it is committed.

Work tree and index
The three main components of a Git project: the repository, index, and working tree.

You can think of this as your basic Git workflow:

  1. Modify your files in the working tree.
  2. Stage the changes you want to include in the next commit.
  3. Commit your changes. (Committing will take the files from the index and store them as a snapshot in the repository.)

Three states of Git files

As you can probably guess from the Git workflow, files can be in one of three states:

  • Modified
  • Staged
  • Committed

When you modify a file, the change will only be found in the working tree. You must then stage the changes if you want to include them in your next commit. Once you finish staging all files, you can commit them and add a message describing what you changed. The modified files will then be safely stored in the repo.

The three file states for Git: modified, staged, and committed.
The three file states for Git: modified, staged, and commited.