git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: What's a "work tree"?

From
Jeff King <peff@peff.net>
Date
Jan 25, 2008, 06:14 UTC
Message-ID
<20080125061421.GC21973@coredump.intra.peff.net>
In-Reply-To
<4798E26D.3040707@talkingspider.com>
On Thu, Jan 24, 2008 at 02:09:33PM -0500, Mike wrote:
> I'm trying to figure out what a "work tree" is.  as in --work-tree. This 
> is a new command right, the tutorials I've read don't have it. The man 
> page has the syntax but I don't know what it's for.

The work tree is the place where your checked out files reside. E.g., in an ordinary repo (made with "git init" or "git clone") everything that isn't in the .git directory.

> $ cd /www/mysitedocroot
> $ git --git-dir /gitdir/mysitegit/ add .
> fatal: add must be run in a work tree

You are using --git-dir to point to a repository directory that isn't ".git". That's OK, and it will generally assume that your current directory is the work tree. E.g., this works:

  mkdir repo && cd repo
  git init
  mv .git mygitdir
  touch file
  git --git-dir=mygitdir add file

However, there is a config option "core.bare" which indicates that a repository is "bare", meaning that it has no work tree (and that is presumably what's happening in your example). So you could use --work-tree=. to override that in your example (though you might just be better off setting config.bare to false).

The more probable use case for --work-tree is something like
  $ cd /gitdir/mysitegit
  $ git --work-tree=/www/mysitedocroot add .

i.e., you are in the git dir, so you specify the work tree rather than the other way around. You could even do this:

  $ cd /some/other/directory
  $ git --git-dir=/gitdir/mysitegit --work-tree=/www/mysitedocroot add .
although I'm not sure it's that useful.
-Peff
Previous: MikeNext: Mike
Message 2 of 4 in “What's a "work tree"?”
  1. MikeJan 24, 2008
  2. Jeff KingJan 25, 2008
  3. MikeJan 25, 2008
  4. Jeff KingJan 25, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.