Re: [idea] separate .git dir and the working tree
Show 9 quoted lines
> what I wanted is, I may have multiple git working tree in my $HOME, like:
> $HOME/proj1
> $HOME/proj2,
>
> I then wanted their .git directories respectively located at
> /safe/disk/.git_proj1
> /safe/disk/.git_proj2
>
> How can I get this? I tried to read the doc but didn't have much luck.
By making .git in $HOME/proj1 a symlink to /safe/disk/.git_proj1 and making $HOME/proj2/.git a symlink to /safe/disk/.git_proj2. GIT_DIR should be left unset for this to work.
The GIT_DIR variable is for more complicated use cases in which you do not want a .git directory, file, or symlink in the worktree at all.
One uses it as follows:
GIT_DIR=/somewhere/else/.git git <command> ...
The top level of the work tree is inferred to be the current working directory and git metadata is taken from somewhere else.
Sometimes a person does not only want to work in the top level of the working tree. To tell git where the top level is, use the GIT_WORK_TREE variable:
(
GIT_DIR=/somewhere/else/.git; export GIT_DIR
GIT_WORK_TREE=$(pwd); export GIT_WORK_TREE
cd sub/directory
git <command>...
cd ../other/directory
git <other command>...
)
These are not variables for your .profile, since as you mentioned, a person typically will work with one git repo and worktree sometimes, another git repo and work tree another time.
Hope that helps, Jonathan
Side note: I don't think you mentioned wanting it, but for reference, there is a nice tool for sharing objects between multiple worktrees in contrib/worktree. It comes with some sharp edges, as described in [1].
[1] http://thread.gmane.org/gmane.comp.version-control.git/150559