31

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

Samir Aguiar
  • 2,509
  • 2
  • 18
  • 32

3 Answers3

28

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

Wenfang Du
  • 8,804
  • 9
  • 59
  • 90
Edward Thomson
  • 74,857
  • 14
  • 158
  • 187
  • 2
    Does it just say "working tree" all the time now? That would be misleading too. If you run `git status .` what you get actually is the status of the working directory. If you run `git status somesubdir` then the result is neither about the current working directory nor about the whole working tree... –  Aug 24 '16 at 17:10
  • @WumpusQ.Wumbley Yes, that's correct. If you provide pathspecs to `git-status` and they are unmodified, then it does say `nothing to commit, working tree clean` even if other parts of the working tree are _not_ clean. I agree this is not optimal, though it's no worse than it was before. – Edward Thomson Aug 24 '16 at 18:44
11

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

Greg Burghardt
  • 17,900
  • 9
  • 49
  • 92
6

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.

Community
  • 1
  • 1
Timothy L.J. Stewart
  • 1,584
  • 19
  • 15
  • 1
    I think to know which is your ***current directory*** you can use the command 'pwd' in the console, right? – Richard Steele Nov 28 '19 at 15:06
  • @RichardSteele Correct. `pwd` is a Unix/Linux (not git) command that means "print working directory", and the usage of "working directory" here is the kind of thing that Linus Torvalds didn't want to trip up git users. Unfortunately, we're about 50 years too late to rename it to `pcd`. – LastStar007 Jun 06 '23 at 18:51