views:

36

answers:

2

When one creates a NEW repository with Git, does the path where the .git subdir is added have to be the SAME one as the path where the project files are (i.e. the files to be managed by Git)? Another way of asking the same question is: If I want to create a new Git repository, does the repository path always have to coincide with the respective project path, or can I create a repository directory in ANOTHER location and then have Git POINT to the project path? For instance, if my Project is in "F:\My Projects\Mother Goose\Gerber\", could I create a Git Repository in say "F:\My Repositories\Pointer Path\Gerber\"? and then tell Git to look in "\My Projects\Mother Goose\Gerber\" for the files to be added to the repository?

+2  A: 

Although it defaults to the current working directory, the repository can be placed anywhere by use of the GIT_DIR environment variable or the --git-dir command line option:

--git-dir=<path>

Set the path to the repository. This can also be controlled by setting the GIT_DIR environment variable. It can be an absolute path or relative path to current working directory.

Mark Rushakoff
+2  A: 

Is there a good reason for which you want this?

Sure, Git fully supports different directory layouts, using the GIT_DIR and GIT_WORK_TREE environment variables (or the corresponding switches). This is very useful in server(-like) scenarios, where users don’t interact with such repositories other than by pulling and pushing – f.ex. in Git-based deployment systems.

But the default layout is the repository in the .git directory at the project root. You can try to work against that, but you will constantly have to tell all the tools you are using about it. It’s not convenient; you’ll be making life difficult for yourself.

So unless you have a solid technical reason (rather than mere preference), I advise against trying to work this way.

Aristotle Pagaltzis