Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does GIT_DIR work? Exactly

Tags:

git

github

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.

like image 822
greduan Avatar asked Aug 02 '26 23:08

greduan


1 Answers

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.

like image 132
CapinWinky Avatar answered Aug 05 '26 13:08

CapinWinky