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

Re: executing git from a non git directory

From
Shawn O. Pearce <spearce@spearce.org>
Date
Jul 22, 2007, 07:07 UTC
Message-ID
<20070722070734.GU32566@spearce.org>
In-Reply-To
<6b6419750707212355q48a934e4n3be0d6111694ad01@mail.gmail.com>
Patrick Aljord <patcito@gmail.com> wrote:
Show 8 quoted lines
> I would like to check it from another direcory, I tried the following 
> command:
> 
> $ git --git-dir=/path/to/my_git_dir status
> 
> and
> 
> $ GIT_DIR='/path/to/my_git_dir' && git status

These are actually the same two commands. The --git-dir option just means "set GIT_DIR before calling the real command".

However, there are two problems here...
 
> but in both cases I get this error:
> fatal: Not a git repository: '/path/to/my_git_dir'

Right. That's problem number 1. /path/to/my_git_dir is probably not actually your Git repository. The git repository is actually in ".git", so you really need to use:

  $ git --git-dir=/path/to/my_git_dir/.git status

However, problem number 2 is that status requires a working directory. Setting GIT_DIR explicitly like this tells git that you don't have a working directory present. So status won't work.

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

That's what you have to do if you want to run git-status. Or use a subshell as that won't change your current working directory:

  $ (cd /path/to/my_git_dir && git status)
-- 
Shawn.
Previous: Patrick AljordNext: Jeff King
Message 2 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.