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.