1

Are there any differences between a repository and a working tree?

These two definitions tell us that a working tree and a repository are projects' files.

It is the repository definition in Github:

A repository contains all of your project's files and each file's revision history. You can discuss and manage your project's work within the repository.

It is the working tree definition in "craftquest" website:

The Work­ing Tree in Git is a direc­to­ry (and its files and sub­di­rec­to­ries) on your file sys­tem that is asso­ci­at­ed with a repository.

phd
  • 82,685
  • 13
  • 120
  • 165
Fox
  • 59
  • 9
  • Is a kitchen counter a component or subset of a refrigerator? – matt Jul 30 '23 at 14:01
  • There are already some good answers below; let me just add something here: A repository can exist without having any working directory. For example, this will be the case on git servers that are just used for collaboration via git. On such servers there will be a git repository, that contains the git history/branches/tags/etc.. But there won't be any working directory, because its not needed. Nobody is going to work there and change the files directly on such server. A git repository without working directory is called a "bare" git repository, I believe. – Jay Jul 31 '23 at 14:38

3 Answers3

3

You can treat repository as your "database" for a project, which stores all the files and the history of changes to those files.

On the other hand, the Working Tree, also known as the Working Directory, is the set of files that corresponds to a single checkout/version of the project.

The main difference is in their functions: the repository (in a version-control system like Git) serves to store and track historical versions of your project, whereas the working tree is your current, editable copy of the project.

3

They are totally different things.

  • The repository is invisible. It is where Git stores history.

  • The working tree is visible. It is where you create history.


From my https://www.biteinteractive.com/picturing-git-conceptions-and-misconceptions/:

I like to say that there are actually three worlds of Git:

The repository. I’m imagining the repository here as consisting (primarily) of stored commits. These are snapshots reflecting past versions of your work.

The index. This is where you configure what you want to go into the next commit.

The working tree. These are files that Git lends you from the repository, so that you can edit them and then add them to the index, in order to tell Git what the index (and hence the next commit) should look like. The working tree is the only part of this triad that you can see directly.

matt
  • 515,959
  • 87
  • 875
  • 1,141
3

Don't forget, as I mentioned with Git 2.5 (July 2015), that you also have multiple working tree.

A git repository can support multiple working trees, allowing you to check out more than one branch at a time.
With git worktree add, a new working tree is associated with the repository.

This new working tree is called a "linked working tree" as opposed to the "main working tree" prepared by "git init" or "git clone".
A repository has one main working tree (if it's not a bare repository) and zero or more linked working trees.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250