Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Working tree vs working directory

Tags:

git

I was reading Git v2.9.1's release notes and one of the changes reads:

"git status" used to say "working directory" when it meant "working tree".

What's the difference between the two? When would git status mean "working tree"?

like image 765
Samir Aguiar Avatar asked Aug 24 '16 16:08

Samir Aguiar


People also ask

What is the difference between Dir and tree?

To put it simply, the "tree" refers to the snapshot of the entire repository state at that moment in time (like what you've got for your current code [which is also known as HEAD], of the repository when the currently checked-out commit was made, etc.) Directory is just referring to a filesystem directory.

What is a working tree?

Th Working Tree in Git is a directory (and its files and subdirectories) on your file system that is associated with a repository. It's full of the files you edit, where you add new files, and from which you remove unneeded files.

What is the difference between working directory and local repository?

The repository is essentially the . git hidden folder inside the working directory (workspace). The working directory (workspace) is essentially your project folder. Also note the term directory is basically synonymous to the term folder.

What is working tree files in Git?

The working tree is the set of all files and folders a developer can add, edit, rename and delete during application development. The status command can provide insight into how the Git working tree behaves. More colloquially, developers often refer to the Git working tree as the workspace or the working directory.


2 Answers

This was done to improve consistency and avoid ambiguity. As explained in the commit that changed this behavior:

Working directory can be easily confused with the current directory.

So this change was made to better disambiguate between the working tree, meaning the location where your repository has been checked out, and the working directory where you are running the git status command, which may be somewhere beneath your working tree (or perhaps not, if you set GIT_WORK_TREE environment variable).

like image 107
Edward Thomson Avatar answered Sep 23 '22 06:09

Edward Thomson


There is a subtle difference in meaning.

A directory is a singular thing -- a folder, a collection of files -- whereas a working tree means a tree like structure of files and directories that are collectively referenced.

Working tree means the directory that contains the .git folder, including all sub directories and files.

To understand this more completely, you have to understand who created Git: Linus Torvalds. Everything in Git is closely related to Linux naming conventions and thought processes, which includes how Git "thinks" about files or the file system:

From 3.1.3. More file system layout

For convenience, the Linux file system is usually thought of in a tree structure. On a standard Linux system you will find the layout generally follows the scheme presented below.

Linux file system diagram

So it's called a "working tree" because Linux kernal/file system developers built Git, and in Linux the file system is thought of as a "tree".

like image 33
Greg Burghardt Avatar answered Sep 20 '22 06:09

Greg Burghardt