#TIL : Put .git data outside project directory

Sometimes you want to put .git data into outside directory (to use another disk partition or to protect your git data). Use --separate-git-dir= option to get that.

Example :

1
$ git init --separate-git-dir=/var/gitstorage/myproject

Bonus : to protect .git data from other users, use this option --shared within octal value (same to chmod)

Example : this will protect git file from writing by group and reading/writing by others

1
$ git init --separate-git-dir=/var/gitstorage/myproject --shared=0640