Here’s my current dir structure:
- mygit
- code
- .git
- morecode
- mycode
- The code folder is monitored by git and git’s files are in the usual code/.git
- I am working only on a piece of this code, i.e. mycode
I’d like to use git to manage my code, but I don’t want its files to be put in the expected code/morecode/mycode/.git, but rather outside of the code folder, e.g. in mygit.
Any ideas how to do that?
My original answer is below, but I’ve rethought this and I don’t think that’s really what you want – I hadn’t noticed on first reading that you only want a subdirectory of the repository there. In any case, using
--git-dirand friends gets confusing fast – you need to remember, for instance, that there’s still only one index (staging area) regardless of where you’re doing git commands from.Instead, I think that really what you want to do is to make
mygita symlink that points to the subdirectory, and then do all your git operations in thecodedirectory.You may want to look at the documentation in the
gitman page, and particularly the sections on the--git-dirand--work-treeoptions and the similarGIT_DIRandGIT_WORK_TREEenvironment variables. You can use these to set arbitrary directories to be your working tree and git directories.One gotcha that’s easy to miss here is if you don’t pass an absolute path to
--git-dir(orGIT_DIR) it will be relative to the working tree, not your current directory.