Three Trees
Definition:

The three main collections of files that a Git user works with. The three collections are:

Referred to by different names both on unofficial websites and by official Git documenation, the three trees are defined inconsistently. The best official definition that I've seen comes from Git Pro, Chapter 7.7, although this is not entirely correct either:

An easier way to think about reset and checkout is through the mental frame of Git being a content manager of three different trees. By “tree” here, we really mean “collection of files”, not specifically the data structure. There are a few cases where the index doesn’t exactly act like a tree, but for our purposes it is easier to think about it this way for now.

Related Terms:

Why The Three Trees Concept Exists:

The reason that the "three trees" exist is to define the locations of user files as they progress from being freely worked on by the Git user to their final destination in the Git repository.

  1. New and altered user files are worked on by the Git user in the working tree. There is nothing special about the working tree. The files are controlled fully by the Git user at the level of the operating system. Git only has an "awareness" that files existing in the working tree may at some point be committed into the local repository.
  2. When the Git user feels the files are ready to be placed into a new commit, the files are staged from the working tree into the staging area. The staging area represents the delta between the last commit in the local repository and the new commit that the Git user wants to create.
  3. When the Git user feels the proper changes have been prepared in the staging area, the changes are committed. This means a new commit object is created and placed into the commit history along with any files that were prepared in the staging area. The staging area is then emptied in preparation for the next round.

Notes:

Used both officially and unofficially, the "Three Trees" are very poorly named. First, there are way too many synonyms. Second, the Git documentation admits they are not trees. (See the quote above.) Why use the term "tree" to describe a collection of files when "tree" has a specific definition in the IT world? (I think the term may have originated from tree objects, but that's not a good reason because "working tree" is a very different concept from a tree object. See the term tree in the Git glossary for the clumsy link between these two terms.) Truly, the definition of "a collection of files" is about the best we can do here. I know we need a way to show the state of the files before staging, after staging, and after committing, but if the Git documentation is going to be revamped, there has got to be better words that could be used.

I understand the usage of "three trees" is deeply ingrained in both official and unofficial documentation, so removal of these terms may not be possible from the documentation. If we are to continue using the idea of the three trees, I suggest using the term staging area and not the currently preferred Git term staging index. I also suggest to completely stop using term "working directory" because the working tree can be more than one directory.

Additionally, the term HEAD is used by official Git documentation, but this is a poor choice. (HEAD is not a collection of files; HEAD is a pointer to a commit.) Atlassian calls the third tree "commit history" which (I think) makes a lot more sense than using the term HEAD. Atlassian didn't make up the term "commit history". Commit history actually comes from official Git documentation. Personally, I wonder if the term "commit history" is still inaccurate. Are we talking about all of the commit history in a repository or are we talking about a single branch?

Sources:

Git Pro (Chapter 7.7, Git Tools - Reset Demystified, The Three Trees)
Git Pro (Chapter 7.7, Git Tools - Reset Demystified, The Index)
Git Pro (Chapter 1.3, Getting Started - What is Git?, The Three States)
Git Pro (Chapter 2.3, Git Basics - Viewing Commit History)

Alternative Source:

Atlassian (Git Reset, Git Reset & Three Trees of Git)

Return to Glossary