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

Re: [DOC] more explanation about --git-dir and --work-tree options

From
Michael J Gruber <michaeljgruber+gmane@fastmail.fm>
Date
Apr 29, 2008, 15:49 UTC
Message-ID
<fv7g2s$g59$1@ger.gmane.org>
In-Reply-To
<48162EF0.6050705@gmail.com>
Liu Yubao venit, vidit, dixit 28.04.2008 22:09:
Show 17 quoted lines
> Hi,
> 
> I find these two options bring me surprise:
> 
>    git init $HOME
>    git add ~/.vimrc ~/.gvimrc ~/.vim
>    cd $HOME/work/xxx
>    ....do some work, then change ~/.vimrc without changing
>        working directory
>    git --git-dir $HOME/.git status
> 
> I use --git-dir because I have another .git in $HOME/work/xxx, the
> last command surprises me much, it tells me .vim* are all deleted!
> 
> After checking the code, I realize git thinks the current working
> directory as top directory of the working tree if --git-dir is specified
> without --work-tree option.

Yes, I found this surprising at first, too. And I noticed later on why things are the way they are, just as you did. :)

More doc on this is certainly helpful.
> And here is my supplement to the documentation.
> +	variable and the '--work-tree' command line option. It can be
> +	a absolute path or relative path to the directory specified by
"an absolute path or a relative...""
> +	--git-dir or GIT_DIR.
> +	Note: If --git-dir or GIT_DIR are specified but none of
> +	--work-tree, GIT_WORK_TREE and core.worktree is specified,
I would probably interchange "is" and "are" here.
Same changes in the following.
I often find myself wanting to operate on a repo without cd'ing to it. While
( cd repo && git command args)
is certainly an option I find the following shell functions helpful:
alias g=git
function gg ()
{
   local _gg="$1";
   shift;
   git --git-dir="${_gg}/.git" --work-tree="${_gg}" "$@"
}
That way,
gg repo command args
runs git in a different location while
g command args
works as usual (and is shorter).

Now I'm just waiting for the experts to tell me that cd'ing to repo is completely different from specifying --git-dir and --work-tree, and that either way is completely wrong. (I'm still stupid and ugly, but I want to become clever and smart.) ;)

Michael
Previous: Liu YubaoNext: しらいしななこ
Message 2 of 3 in “[DOC] more explanation about --git-dir and --work-tree options”
  1. Liu YubaoApr 28, 2008
  2. Michael J GruberApr 29, 2008
  3. しらいしななこApr 29, 2008

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.