5

In my experience so far with reading about GIT, I have found that Working Directory seems to be a bit of an overloaded term. Sometimes people mean the directory on the hard drive into which a branch is checked out e.g. when cloning a repo, the branch is checked out into the directory of the new clone of the repo.

But sometimes people just mean an abstract location which contains untracked files and modified files i.e. the red text when you enter git status

I was hoping someone could give me an idea of the official definition of the working directory. Even that online Pro Git book seems to be a bit vague as to exactly what it is.

Note: I use it every day, I just want to know what it is.

Cheers

onefootswill
  • 3,707
  • 6
  • 47
  • 101
  • Where exactly do you see the difference between the two? The directory on the hard drive that you work on is what contains your modifications. But I think the term is "working copy". – Thilo May 13 '15 at 03:50
  • @Thilo Ah yes, I've read that term too. So, different concepts and different terms, all overloaded. The difference between the 2 is that the 2nd concept does not include unmodified files which are being tracked. Only modified files. – onefootswill May 13 '15 at 04:00

3 Answers3

7

From git commit-tree, a tree represents a particular directory state of a working directory.

So while the working directory represents where a repo is checked out, a working tree represents its status.
A git status shows a "working tree", meaning the state of a working directory.

A working directory references the "where", a working tree references the "what" (what it contains, its files tracked or not tracked)

Note that git 2.5 (Q2 2015) will allow multiple working trees for a given local repo.
That means you will use multiple working directories (with git worktree add <path> [<branch>]), and each working directory can contain a different working tree: you can checkout different branches per path, for instance, which means each directory contains a different state of the same repo: multiple working trees.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I think I'll be marking this as the answer, as it really hits the mark and answers the question. On that note, is Working Tree a synonym for Working Copy? – onefootswill May 14 '15 at 04:23
  • 1
    @onefootswill I suppose, but I always use working tree because of the `--work-tree` option you can add to the git command. – VonC May 14 '15 at 06:52
  • Cool. Just trying to sort through these terms. I think I will use Working tree as well. – onefootswill May 14 '15 at 08:48
4

Maybe this helps.

There is basically three things you have on your local computer when working with a git repository:

1) The repository itself. Contains the whole change history of the project. Commits, trees, blobs. This is stored inside the .git directory.

2) Your working copy. It is created when you "checkout" code (a branch usually) from the repository. It starts out having all the files you checked out from the repository, but you can work on them. These are stored in regular files outside of the .git directory.

3) A staging area called "index". When you commit to the repository, you first "add" your changes to the index. That basically takes a snapshot of the files you want to commit. You can then atomically commit all these changes. Or review them. Or add some more. The index is also stored inside of the .git directory.


Untracked files: Those are just files that you have in your working copy that are not part of the repository.

Modified files: Those are files that have different contents in your working copy then they do in the repository. They can be already "staged" (i.e. added to the index) or not.

When you run something like git status or git diff, the tooling looks at the contents of the files in your working copy and compares them to the repository (and index). The file status is not something that is "stored" anywhere, it is computed on the fly.

Thilo
  • 257,207
  • 101
  • 511
  • 656
  • I was on top of 1 and 3 already. 2 makes sense to me. It's all the checked out files. I think it includes unmodified files, even though people say it is untracked and modified files only. A confusing area, only because people don't use exactitude in their language. Or possibly don't understand the minutiae themselves. – onefootswill May 13 '15 at 04:06
  • Also note that when you do a git status, it refers to the Working Directory, not the Working Copy. Interesting. – onefootswill May 13 '15 at 04:09
  • Where does it refer to "Working Directory"? My "git help status" says "Working Tree", which does not make things better.... – Thilo May 13 '15 at 04:14
  • where it says to use the checkout command if you want to discard changes. – onefootswill May 13 '15 at 04:21
1

The directory the .git directory is placed in and all (not excluded) directories under that.

bish
  • 3,381
  • 9
  • 48
  • 69
  • which correlates to the first concept I put in bold (not including the words Working Directory). So, it is definitely that as distinct from just untracked and modified files? – onefootswill May 13 '15 at 04:02
  • This isn't necessarily true since the location of the .git directory can be changed with the GIT_DIR environment variable or the `--git-dir` command line option. – Magnus Bäck May 13 '15 at 05:47