Reputation: 4938
This is not clear at all for me: http://git-scm.com/2010/04/11/environment.html
From what I can figure, I can't do it for individual repos. The commands are just not clear enough...
From what I can figure, I can do it like this:
GIT_DIR="directory here"
However, this seems like it's a global directory for Git repos' Git folder. Is it like this?
How exactly can I set the Git directory for only THIS repo?
Thanks for your help. If it's too stupid, I'm sorry but it's really confusing for me.
Upvotes: 3
Views: 8583
Reputation: 824
You can relocate the repository folder of any repo by replacing the .git
folder with a .git
file that contains gitdir: <path>
. That path will be to another folder that will act as your repository folder.
NOTE: <path>
contains the name of the repository folder and is not simply a path to a .git
folder.
You could use this to store all repository folders in a single location with unique names. You sill execute git commands in the location of the .git
file.
GIT_DIR, GIT_WORK_TREE, etc are just environment variables that, if set, are used by git. IF you set them globally they will apply globally and probably mess everything up. If they are set when you do git init
it will create the repo with the appropriate config to continue working after the env are unset.
Upvotes: 5
Reputation: 174299
If you are using the environment variable, you have to set it for every repository before using it. You can do this by starting your shell / program via a special batch file that sets the correct environment variable. Like this, it won't affect other processes, because the environment variable will be set only for the current process and its children.
There is no permanent way to assign a certain GIT_DIR value to a certain folder on your disk, because without a .git directory, there is no way to store this info.
Upvotes: 2