I’ve read a number of posts that seem to get me close but not all the way to what I’d like. I have one server. On it, I have 3 websites: http://www.domain.com, staging.domain.com, and dev.domain.com. I also develop on local.domain.com and also use GitHub as my central repo.
I’d like to keep my git repositories out of my web roots. I’m open to how to do this. What I’m trying is:
/home/user/git/production.git
/home/user/git/staging.git
/home/user/git/development.git
I know how to do this if there’s only 1 site and repo by setting GIT_DIR and GIT_WORK_TREE (I export the paths in .bash_profile).
It seems I can set the working tree within each repository’s config, like:
[core]
bare = false
worktree = /home/user/domains/www.domain.com/public_html
But how do I set GIT_DIR?
So if I’m in /home/user/domains/www.domain.com/public_html and do a git status, etc., it’s referring to the production git repo. And if I’m in /home/user/domains/staging.domain.com/public_html, it is tied to staging.git.
Rather than setting
$GIT_DIRyou could use gitlink files. To do this simply go into the root of each working tree and run:This would result in a
.gitfile in your web root, but the only thing that would leak if somebody accessed that would be the path to the repository. This would avoid needing to play games with setting the$GIT_DIRvariable based on which directory you’re in.