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

Need to set GIT_WORK_TREE when setting GIT_DIR !?

From
FHFrédéric Heitzmann <frederic.heitzmann@gmail.com>
Date
Mar 9, 2012, 22:51 UTC
Message-ID
<CALeToSUaPzdr=u7FfwHEtEanphVP5LZ09QdQXno52PLBTK0H-g@mail.gmail.com>
Hi all,

I want to set GIT_DIR to another path than <project_dir>/.git. Unfortunately, git add or git status failed with the following error:

fatal: This operation must be run in a work tree
Unless I also set GIT_WORK_TREE, git status|add|stash|clean|... always fail.

git or git-config man pages does not state anything like this. Did I miss something ?

#test-case :

export GIT_DIR=$PWD/.gita && git init echo "file a" >> a.txt && git add a.txt #fail git status #fail

export GIT_WORK_TREE=$PWD git status #pass git add a.txt && git commit -m'file a' #pass

unset GIT_WORK_TREE git status #fail, it does not look like some bug related to a newly created, empty repository

Note: that using --git-dir instead of GIT_DIR give the same errors.

-- Fred

Next: Junio C Hamano
Message 1 of 7 in “Need to set GIT_WORK_TREE when setting GIT_DIR !?”
  1. Frédéric HeitzmannMar 9, 2012
  2. Junio C HamanoMar 9, 2012
  3. Frédéric HeitzmannMar 10, 2012
  4. Nguyen Thai Ngoc DuyMar 10, 2012
  5. Junio C HamanoMar 10, 2012
  6. Jonathan NiederMar 10, 2012
  7. Frédéric HeitzmannMar 11, 2012

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.