I’m sorry if this is a duplicate, I’ve searched google and SO and couldn’t find anything similar since it’s a fairly generic set of words to search for!
What I want is to have the .git directory be outside of the working tree.
I need to do this because it’s a ‘stealth’ git repository inside a project using other version control software, and unfortunately the way it is set up is with multiple projects (which I want to each be a git repository) inside one root directory, and with build scripts that like to purge files from the project directories. So far I’ve been versioning the root directory and ignoring all other project directories, so one of the projects was versioned, but I now want to version another project and clearly can’t have multiple git repositories in the root directory (or can I? That would be a good alternative answer). Putting the .git directories elsewhere on disk would be a good solution, if it’s possible.
You can specify the path to the git repository explicitly with the
--git-dirglobal option for all git commands. When you use this option withinitit usually creates a bare repository but if you supply--work-treeas well you can initialize a non-bare repository with a ‘detached’ working tree.From then on, you still have to supply either the
--git-diroption or setGIT_DIRenvironment variable so that git knows where the repository is as there is no git specific data at all inside the working tree, but the working tree will be determined appropriately from the git repository config.