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

Re: how to git a read only directory

From
Michael J Gruber <git@drmicha.warpmail.net>
Date
Jan 21, 2009, 09:57 UTC
Message-ID
<4976F195.9030908@drmicha.warpmail.net>
In-Reply-To
<20090121083354.GG6970@b2j>
bill lam venit, vidit, dixit 21.01.2009 09:33:
Show 7 quoted lines
> I want to use git to keep track of files inside /etc but do not want
> to do it as a super user. Is that possible to put GIT_DIR under my
> home directory and add public-read files inside /etc? Or that it could
> be done in some other ways.
> 
> Thanks.
> 

You can use the core.worktree config variable in order to specify a worktree (/etc) which is not directly above .git. For your git commands to find the .git dir you would need to set GIT_DIR or use the --git-dir parameter.

I have found, though, that several git commands require you to be within the worktree or else they become confused. I use a shell function for that, doing something like "gg ~/path/project log" which requires ~/path/project.git to have its core.worktree set. Also, having a git alias like "git view" set up for gitk helps calling gitk in that way. git-gui makes unfounded assumptions and is completely unhappy in a situation like that.

I think the situation around GIT_DIR and and worktree is a bit in the flux at the moment (panta rhei..) but it works for me.

Cheers, Michael

Here's the "git go" bash function. I'm not proud of it, it makes several assumptions and does no error checking. Use it like "gg path/project command parameters" if the git-dir is "path/project.git" or "gg path/project/" if the git-dir is "path/project/.git". Have your core.worktree set in the former case, and also in the latter if the worktree is not "path/project".

I'm sure it can be done much better using helper functions from git's bash-completion, e.g.

gg ()
{
    local _gg="$1";
    shift;
    local _ggwt=`git --git-dir="${_gg}.git" config --get core.worktree`;
    if [ -z "${_ggwt}" ]; then
        _ggwt=$(cd ${_gg} 2> /dev/null && pwd -P);
    fi;
    local _gggd=$(cd ${_gg}.git 2> /dev/null && pwd -P);
    pushd ${_ggwt} > /dev/null;
    git --git-dir=${_gggd} "$@";
    popd > /dev/null
}
Previous: bill lamNext: bill lam
Message 2 of 10 in “how to git a read only directory”
  1. bill lamJan 21, 2009
  2. Michael J GruberJan 21, 2009
  3. bill lamJan 21, 2009
  4. Boaz HarroshJan 21, 2009
  5. bill lamJan 21, 2009
  6. Boaz HarroshJan 21, 2009
  7. bill lamJan 22, 2009
  8. Boaz HarroshJan 22, 2009
  9. bill lamJan 22, 2009
  10. Boaz HarroshJan 22, 2009

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.