2

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.

2 Answers 2

3

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.

2

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.

3
  • I see... So basically if I this feature, I gotta use it for every repo?
    – greduan
    Apr 2, 2013 at 16:44
  • @Eduan: Only if you specify GIT_DIR as a global environment variable and not one bound to your process. Apr 2, 2013 at 17:25
  • I see. Thanks for clarifying, and your answer. :)
    – greduan
    Apr 2, 2013 at 18:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.