Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the Working Directory of a GIT repository?

Tags:

git

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

like image 601
onefootswill Avatar asked May 13 '15 03:05

onefootswill


People also ask

What is a working directory in Git?

As stated in the Git Documentation: The working directory is a single checkout of one version of the project. This essentially means if you checkout a branch (e.g. master) and are sat on a particular commit (e.g. HEAD), your working directory is the "umbrella" term for all your files and folders.

What is working directory in 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 directory is Git repository?

The Local Repository is the . git/ subdirectory inside the Working Directory.

What are the Git directory and the 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.


1 Answers

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.

like image 127
VonC Avatar answered Nov 15 '22 05:11

VonC