开发者

Setting up .git folder in a custom location

Here's my current dir structure:

  1. The code folder is monitored by git and git's files are in the usual code/.git
  2. 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?


Also, instead of using a symbolic link, you can simply make .git a regular file and put a path in it:

$ echo gitdir: /path/to/gitdir > .git


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜