Jeff King <p...@peff.net> writes:
> 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
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.
> 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.
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html