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-dir
and 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 mygit
a symlink that points to the subdirectory, and then do all your git operations in the code
directory.
You may want to look at the documentation in the git
man page, and particularly the sections on the --git-dir
and --work-tree
options and the similar GIT_DIR
and GIT_WORK_TREE
environment 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
(or GIT_DIR
) it will be relative to the working tree, not your current directory.