Re: I don't want the .git directory next to my code.
- From
Wayne Davison <wayne@opencoder.net>
- Date
- Jan 16, 2008, 22:33 UTC
- Message-ID
- <20080116223333.GB17142@blorf.net>
- In-Reply-To
- <alpine.LNX.1.00.0801152305050.13593@iabervon.org>
On Tue, Jan 15, 2008 at 11:13:58PM -0500, Daniel Barkalow wrote:
Show 6 quoted lines
> export GIT_DIR=/somewhere-else.git > > Note that this only really works if you've only got one repository; > there's no good way to have the repository information outside of the > working directory and still have which repository you're using depend on > which directory you're working in.
If you use zsh as your shell, put this chpwd function in .zprofile or .zshrc:
chpwd() {
local gitbasedir=/var/local/git
local subdir=$gitbasedir$PWD
while [[ ! -d $subdir ]]; do
subdir=${subdir:h}
done
if [[ -d $subdir/.git ]]; then
export GIT_DIR=$subdir/.git
export GIT_WORK_TREE=${subdir/$gitbasedir/}
else
unset GIT_DIR GIT_WORK_TREE
fi
}Then, for each /path/.git dir, move it to /var/local/git/path/.git (creating any needed parent dirs). On every change of directory in the shell, the variables GIT_DIR and GIT_WORK_TREE will be either updated or cleared. If you ever move a work-tree dir, you'll need to remember to move the .git dir in the /var/local/git hierarchy.
..wayne..