Samir Aguiar
Samir Aguiar

Reputation: 2559

Working tree vs working directory

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"?

Upvotes: 34

Views: 12227

Answers (4)

m___
m___

Reputation: 111

Answering the spot on remark above "working directory tree":

"is your current directory plus all the directory paths in it, if it were me, I'd rename it to 'working directory tree' so the term 'tree' lends itself more to a directory structure in your minds eye and less to a git tree structure"

This is the most pertinent remark, the only precise description. "The tree structure branching out, from the directory one issues the git command from(working directory). This describes precisely in all cases the "git" meaning of "working tree" and "git working directory"

This would avoid a lot of confusing explanations on all issues git. Then there is to be "the filesystem" vocabulary, where "working directory of the file system"(always corresponding to the $(pwd) command), which is not necessarily the same directory on the filesystem as the "git working directory" (in the case of commands example: "git -C /path/to/dir status" commands.

A lot of confusion could be avoided, some commands are dangerous, even, and especially when the tutor means well, because of the confusing terminology.

This is the problem with almost all code, where the terminology becomes cryptic but to insiders.

Git sits on the filesystem, it is not a different layer, so it should respect the "linux/unix" conventions, then add to them, if necessary. That is why we have sub-commands in the first place "git(meaning different from) rm" instead of rm which in it's various combinations can do most of the "git rm ..." jobs.

Upvotes: 0

Edward Thomson
Edward Thomson

Reputation: 78673

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).

Upvotes: 30

Timothy L.J. Stewart
Timothy L.J. Stewart

Reputation: 1754

Current directory

is your current folder, command line ls list the items in your current directory

Working tree

is your current directory plus all the directory paths in it, if it were me, I'd rename it to 'working directory tree' so the term 'tree' lends itself more to a directory structure in your minds eye and less to a git tree structure

Working directory

is ambiguously used to refer to both of these cases, don't use this word. It confuses everyone.

Upvotes: 9

Greg Burghardt
Greg Burghardt

Reputation: 18783

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".

Upvotes: 11

Related Questions