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

Re: git ate my home directory :-(

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 26, 2013, 18:20 UTC
Message-ID
<7vfvzit439.fsf@alter.siamese.dyndns.org>
In-Reply-To
<20130326174059.GA10383@sigill.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 11 quoted lines
> Yes, setting GIT_DIR but not GIT_WORK_TREE has always been a valid way
> to work on a repository where you do not want the working tree polluted
> with your .git file. It's not a common setup, but people do use it.
> E.g., you might keep ~/mail as a git repo, but do not want the presence
> of ~/mail/.git to confuse your mail tools. You can keep ~/git/mail.git
> as just a repository, and do "cd ~/mail && GIT_DIR=~/git/mail.git git
> foo" (or "git --git-dir=~git/mail.git foo").
>
> Later, we introduced GIT_WORK_TREE (and core.worktree), which provided
> another way of doing the same thing (instead of the "cd", you could set
> GIT_WORK_TREE).
A small correction is necessary as the above invites confusion.

When you are in ~/mail/subdir, because GIT_DIR alone does not give you to specify where the root-level of the working tree is, you had to "cd .." before running "GIT_DIR=~/git/mail.git git ...". By setting GIT_WORK_TREE to point at ~/mail once, you can freely chdir around inside subdirectories of ~/mail without losing sight of where the root-level is, and if your ~/git/mail.git is tied to a single working tree (and that is true in this example, it is always ~/mail), you can even set core.worktree in ~/git/mail.git/config.

These two mechanisms are *not* about allowing you to run git from any random place, e.g. "/tmp".

> For the most part, I'd expect setting core.worktree to be the
> simplest for such setups, as once it is set, you can just do "cd
> ~/git/mail.git git foo", and everything should just work.
Yes.
> We could do so now, as long as we provide an escape hatch (and I think
> spelling that hatch as GIT_WORK_TREE=. is probably sane, but I am open
> to other suggestions).

If we were to do so, GIT_WORK_TREE=. would be the most sensible, but I do not think it is worth breaking. Why do these people set GIT_DIR without setting GIT_WORK_TREE in the first place?

That is the source of the confusion. Perhaps some random but popular websites are spreading bad pieces of advice?

> The problem is not with "clean", which just happens to be a destructive
> command, but rather with the notion of what the git tree is when you
> provide GIT_DIR.

Yes, "git add ." would happily add random cruft to your index, which is equally bad.

Previous: Jeff KingNext: Jeff King
Message 26 of 35 in “git ate my home directory :-(”
  1. Richard WeinbergerMar 25, 2013
  2. Jonathan NiederMar 25, 2013
  3. Junio C HamanoMar 25, 2013
  4. Jonathan NiederMar 25, 2013
  5. Junio C HamanoMar 25, 2013
  6. Junio C HamanoMar 25, 2013
  7. Richard WeinbergerMar 25, 2013
  8. Jonathan NiederMar 25, 2013
  9. Junio C HamanoMar 25, 2013
  10. Richard WeinbergerMar 25, 2013
  11. Jonathan NiederMar 25, 2013
  12. Brandon CaseyMar 25, 2013
  13. Philip OakleyMar 26, 2013
  14. Duy NguyenMar 26, 2013
  15. Jeff KingMar 26, 2013
  16. Junio C HamanoMar 26, 2013
  17. Duy NguyenMar 27, 2013
  18. Philip OakleyMar 26, 2013
  19. Richard WeinbergerMar 26, 2013
  20. Jeff KingMar 26, 2013
  21. Richard WeinbergerMar 26, 2013
  22. demerphqMar 26, 2013
  23. Jeff KingMar 26, 2013
  24. demerphqMar 26, 2013
  25. Jeff KingMar 26, 2013
  26. Junio C HamanoMar 26, 2013
  27. Jeff KingMar 26, 2013
  28. 1/3 environment: set GIT_WORK_TREE when we figure out work treeJeff King, Mar 26, 2013
  29. Jonathan NiederMar 26, 2013
  30. 2/3 setup: warn about implicit worktree with $GIT_DIRJeff King, Mar 26, 2013
  31. Jonathan NiederMar 26, 2013
  32. Jeff KingMar 26, 2013
  33. Jonathan NiederMar 26, 2013
  34. Matthieu MoyMar 27, 2013
  35. 3/3 setup: treat GIT_DIR without GIT_WORK_TREE as a bare repoJeff King, Mar 26, 2013

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.