Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

keep git files in another folder

Tags:

git

How can I set up git to keep track of files in folder ~/a , but store the .git folder in folder ~/b?

Also, to take this one (huge) step further, can I keep the .git folder on another server and run git commands from server a to check git st for example, on server b?

Basically, i'd like to to able to use git on a certain folder without keeping the .git directory in that same folder. and for my second question above, i'd like to take that one step further by not even keeping the .git directory on the same server

Thanks!

like image 619
d-_-b Avatar asked Jun 30 '13 15:06

d-_-b


1 Answers

Set the GIT_DIR environment variable.

In bash:

export GIT_DIR=~/b

or, in PowerShell:

Set-Item env:GIT_DIR $env:HOME\b

Alternatively you can use the --git-dir command line parameter on all git commands:

git --gir-dir=~/b status

See this article about git environment variables

About putting the Git repository directory on another server: well, as long as you have mounted the file system from that server and have appropriate permissions, that should work fine. The git commands that operate on your local directory care mostly about accessing the file system, so they work as long as that works.

(To clarify: Above I am assuming that ~/b is the git directory, if .git is a subdirectory of ~/b, you should use ~/b/.git instead)

like image 98
Klas Mellbourn Avatar answered Nov 10 '22 12:11

Klas Mellbourn