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

Re: [git-users] Problem using detached worktrees with commands implemented in scripts

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 17, 2013, 20:08 UTC
Message-ID
<xmqq4n8fzmmj.fsf@gitster.dls.corp.google.com>
In-Reply-To
<201310171909.r9HJ9mxd007908@freeze.ariadne.com>
worley@alum.mit.edu (Dale R. Worley) writes:
Show 7 quoted lines
> I must admit I've never seen the design (and I personally doubt that
> the design has ever been written down).  But at least the following
> commands work correctly on a detached worktree if the current
> directory contains the .git directory, because I am using them in a
> production manner:
>
>     git add
If you have this:
	/repositories/proj.git/{refs,objects,...}
	/working/trees/proj-wt1/

where proj-wt1 is a working tree for that proj.git repository, the idea was to set these:

	GIT_DIR=/repositories/proj.git
        GIT_WORK_TREE=/working/trees/proj-wt1
        export GIT_DIR GIT_WORK_TREE

and then working in /working/trees/proj-wt1 or any of its subdirectory should work as if you did not have these two environment variables and had /working/trees/proj-wt1/.git instead of /repositories/proj.git as the repository. To make that use case work was the motivation behind these environment variables.

	Side note: without GIT_WORK_TREE environment (or
	core.worktree), there is no way to tell where the top level
	is, so you were limited to always be at the top level of
	your working tree if you used GIT_DIR to refer to a
	repository that is not embedded in your working tree.  There
	were some changes in this area, but I do not recall the
	details offhand.
Now, when you say "the cwd contains the .git directory", do you mean
	cd /repositories
        git add ../working/trees/proj-wt1/file

updates "file" in the /repositories/proj.git/index? Or do you mean this?

	cd /repositories/proj.git
        git add ../../working/trees/proj-wt1/file
Or this?
	cd /repositories
	edit ../working/trees/proj-wt1/file
	git add file

Most of the commands you listed do not need to look at the actual working tree files, so I would expect e.g. "git log" or "git log paths..." to work but I am wondering what your definition of "works" with respect to the pathspecs, especially when you talk about starting Git command _outside_ the working tree (whether the working tree has its repository embedded in it is not very relevant).

Previous: Dale R. WorleyNext: Dale R. Worley
Message 13 of 17 in “[git-users] Problem using detached worktrees with commands implemented in scripts”
  1. Dale R. WorleyOct 16, 2013
  2. Junio C HamanoOct 16, 2013
  3. Philip OakleyOct 16, 2013
  4. Junio C HamanoOct 16, 2013
  5. Philip OakleyOct 17, 2013
  6. Junio C HamanoOct 17, 2013
  7. Philip OakleyOct 17, 2013
  8. Philip OakleyOct 17, 2013
  9. Jonathan NiederOct 17, 2013
  10. Philip OakleyOct 18, 2013
  11. Dale R. WorleyOct 18, 2013
  12. Dale R. WorleyOct 17, 2013
  13. Junio C HamanoOct 17, 2013
  14. Dale R. WorleyOct 18, 2013
  15. Junio C HamanoOct 18, 2013
  16. Dale R. WorleyOct 21, 2013
  17. Dale R. WorleyOct 18, 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.