Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git: Where exactly is the "working directory"?

I am going through some Git tutorials. The concept of a "working directory" keeps being mentioned, however, none of the tutorials or documents I read points out where or what this "working directory" is.

I have thought that it was actually the .git's parent directory, a.k.a the directory I run git init in. But the video tutorial I am watching talks about the state of nothing to commit and "working directory clean":

In fact you can actually make a copy of the repository, and make that copy so that it does not have a working directory, this is actually called the bare clone. This is actually what GitHub uses.

If my understanding of the "working directory" is correct, how can a repository not have a "working directory"? And what does it mean, when it says that GitHub uses a "bare clone"?

like image 605
shenkwen Avatar asked Mar 24 '16 13:03

shenkwen


4 Answers

This should hopefully clear things up for us:

What is the difference between a repository created using the git init command and the git init --bare command?

Repositories created with the git init command are called working directories. In the top level folder of the repository you will find two things:

A .git subfolder with all the git related revision history of your repo
A working tree, or checked out copies of your project files.

Repositories created with git init --bare are called bare repos. They are structured a bit differently from working directories. First off, they contain no working or checked out copy of your source files. And second, bare repos store git revision history of your repo in the root folder of your repository instead of in a .git subfolder. Note… bare repositories are customarily given a .git extension.

Taken from John Saints - What is a bare git repository?

A bare git clone does not contain a working directory of checked out code, in other words.
Think of it as just the .git directory (the Git database) without anything else.

like image 157
jacmoe Avatar answered Oct 08 '22 03:10

jacmoe


It's wherever you have checked out the project. For example the directory within which you have checked out a branch of your project. It's typically the folder that contains the .git folder. That is the working directory. When you make changes to files in your checked out branch you make changes to the working directory. At this point the working directory has uncommitted changes. So initially, when you haven't made any commits, the working directory will be clean as there are no changes.

like image 45
Som Bhattacharyya Avatar answered Oct 08 '22 04:10

Som Bhattacharyya


The working directory is simply, your current local directory that you are working on. e.g if you have master, dev and yourname-dev as your remote branches, if you checkout from dev to yourname-dev, yourname-dev is now your working directory if you checkout from this (yourname-dev) working directory to another say dev, dev is now your new working directory

like image 31
Babajide Apata Avatar answered Oct 08 '22 04:10

Babajide Apata


To kind of combine the two other answers:

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.

It isn't a particular directory/folder though. The working directory covers all directories, files...everything.
I mention this because when you want to commit some files, those files will be in the working directory and you'll need to stage them (using git add) before committing them (using git commit).

like image 27
Harmelodic Avatar answered Oct 08 '22 05:10

Harmelodic