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

Re: [RFC] introduce GIT_WORK_DIR environment variable

From
Linus Torvalds <torvalds@linux-foundation.org>
Date
Mar 11, 2007, 20:37 UTC
Message-ID
<Pine.LNX.4.64.0703111326170.9690@woody.linux-foundation.org>
In-Reply-To
<7vabykxs15.fsf@assigned-by-dhcp.cox.net>
On Sat, 10 Mar 2007, Junio C Hamano wrote:
Show 12 quoted lines
> Matthias Lederhofer <matled@gmx.net> writes:
> > Idea:
> > Add some way to configure tho working directory for one repository
> > and set GIT_WORK_DIR automatically when GIT_DIR is used.  I think of:
> >  * a subdirectory in the repository directory
> >    e.g. .git/work_dir which is supposed to be a symlink (or a textfile
> >    containing the path for windows compatibility?)
> > or
> >  * a configuration variable
> 
> I am not sure why you bother.  Obviously I am missing a few
> useful use cases you and Nguyen have in mind.

I actually like this feature. Let me explain why I think it's a great feature:

Show 5 quoted lines
> But either .git/work_dir or a configuration means you are
> linking a repository with a _single_ working tree, permanently.
> If you are permanently linking one repository with a _single_
> working tree, is it too much bother to have that repository at
> the usual $GIT_TOP_DIR/.git like everybody else?

I'll tell you why: it makes tons of sense to have the git repository linked to exactly one working tree, *but the reverse is not necessarily always true*!

In other words, it can be a 1:n relationship.

You can have one working tree that is related to *multiple* git repositories.

That sounds insane, but I actually think it works, and makes tons of sense. Think something as simple as your own home directory.

It's possible that you want to track your music collection with git, but say that your music collection is a few different subdirectories or files in your home directory: maybe you track your "Music" directory (which contains the actual mp3 files or whatever), but maybe you'd like the same repository to *also* track things like your configuration file for whatever mp3-player you're using (".xmms"? Whatever).

So let's say that you have a git repository for tracking all that. The "working tree" for that git repository would be your home directory.

Now, imagine that you *also* want to track something else in git, that you *also* have in your home directory. Say your ".bashrc" files etc. They have nothing to do with your music tracking setup, so you don't want to track it in the same git repository, and you want to have a totally different .git/index file for those. But again, the *working*tree* is actually your home directory.

So allowing you to set the working tree associated with a particular git repository actually solves that problem. They can both share the same working tree (you'd want to track disjunct parts of the working tree, of course), which means that the working tree obviously does *not* want to have a .git/ directory in it. And to track your music changes, you'd just do

	cd music-repository
	git add music/
	git commit
to add any new files, and you'd be all set (or something like this).

There are other cases than just your home directory where you might want to track disjoint filesets in different git repositories. Things like /etc fall under the same "many unrelated things in the same working tree" setup.

So I actually think it makes tons of sense to allow a way to set the working tree for a git repository, and go the other way.

		Linus
Previous: Johannes SchindelinNext: Junio C Hamano
Message 7 of 39 in “[RFC] introduce GIT_WORK_DIR environment variable”
  1. Matthias LederhoferMar 11, 2007
  2. Junio C HamanoMar 11, 2007
  3. Andy ParkinsMar 11, 2007
  4. Matthias LederhoferMar 11, 2007
  5. Junio C HamanoMar 11, 2007
  6. Johannes SchindelinMar 11, 2007
  7. Linus TorvaldsMar 11, 2007
  8. Junio C HamanoMar 11, 2007
  9. Linus TorvaldsMar 11, 2007
  10. A.J. RossiniMar 12, 2007
  11. Andy ParkinsApr 1, 2007
  12. Nguyen Thai Ngoc DuyMar 11, 2007
  13. Matthias LederhoferMar 11, 2007
  14. Nguyen Thai Ngoc DuyMar 11, 2007
  15. Matthias LederhoferMar 11, 2007
  16. Nguyen Thai Ngoc DuyMar 11, 2007
  17. introduce GIT_WORK_DIR environment variableMatthias Lederhofer, Mar 11, 2007
  18. Nguyen Thai Ngoc DuyMar 11, 2007
  19. use $GIT_DIR/workdir as working directory with $GIT_DIRMatthias Lederhofer, Mar 11, 2007
  20. core.workdir config variableMatthias Lederhofer, Mar 13, 2007
  21. core.workdir config variableMatthias Lederhofer, Mar 13, 2007
  22. Shawn O. PearceMar 14, 2007
  23. Junio C HamanoMar 14, 2007
  24. Shawn O. PearceMar 14, 2007
  25. Nguyen Thai Ngoc DuyMar 11, 2007
  26. rev-parse: --is-bare-repository optionMatthias Lederhofer, Mar 11, 2007
  27. git-init: set up GIT_DIR/workdir if GIT_WORK_DIR is setMatthias Lederhofer, Mar 12, 2007
  28. Joshua N PritikinMar 12, 2007
  29. Matthias LederhoferMar 12, 2007
  30. Matthias LederhoferMar 12, 2007
  31. Nguyen Thai Ngoc DuyMar 12, 2007
  32. Matthias LederhoferMar 12, 2007
  33. Junio C HamanoMar 12, 2007
  34. Matthias LederhoferMar 12, 2007
  35. always interpret GIT_WORK_DIR relative to $GIT_DIRMatthias Lederhofer, Mar 12, 2007
  36. GIT_WORK_DIR: documentation for relative pathMatthias Lederhofer, Mar 12, 2007
  37. Junio C HamanoMar 12, 2007
  38. Matthias LederhoferMar 12, 2007
  39. git-init: set up GIT_DIR/workdir if GIT_WORK_DIR is setMatthias Lederhofer, Mar 12, 2007

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.