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

Re: executing git from a non git directory

From
Jeff King <peff@peff.net>
Date
Jul 22, 2007, 07:11 UTC
Message-ID
<20070722071136.GA346@coredump.intra.peff.net>
In-Reply-To
<6b6419750707212355q48a934e4n3be0d6111694ad01@mail.gmail.com>
On Sun, Jul 22, 2007 at 01:55:33AM -0500, Patrick Aljord wrote:
Show 8 quoted lines
> $ git --git-dir=/path/to/my_git_dir status
>
> and
>
> $ GIT_DIR='/path/to/my_git_dir' && git status
>
> but in both cases I get this error:
> fatal: Not a git repository: '/path/to/my_git_dir'

A git dir is the location where all of the repository information is stored; it is called '.git' for a directory with a working tree. Is /path/to/my_git_dir really a git dir, or is it a working directory that has a '.git' inside it?

If the latter, then you need to specify the .git directory. However, running 'git-status' won't make any sense then, since you won't be in the correct working tree (so of course it will look like files have been removed).

You could do something like "git --dir /path/to/my_git_dir/.git branch" and it would at least produce sensible results.

> yet when I do "$ cd /path/to/my_git_dir && git status" I do get the results.

Right. That's the way you have to do it in the case of 'status', since you need your current working directory to be in the right place.

If you are running a very recent git, you can now try:
  git --work-tree=/path/to/my_git_dir --git-dir=/path/to/my_git_dir/.git status
which is what you actually want.
-Peff
Previous: Shawn O. PearceNext: Patrick Aljord
Message 3 of 4 in “executing git from a non git directory”
  1. Patrick AljordJul 22, 2007
  2. Shawn O. PearceJul 22, 2007
  3. Jeff KingJul 22, 2007
  4. Patrick AljordJul 22, 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.