d-_-b
d-_-b

Reputation: 23191

keep git files in another folder

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!

Upvotes: 6

Views: 462

Answers (2)

Jokester
Jokester

Reputation: 5617

An alternative way: you can specify real path of .git folder in a file, and redirect operations to it.

For example, create a text file A/.git and fill it with

gitdir: B/.git                # assume B is a non-bare repo

Then you can have a work tree in A, which uses .git folder in B.

BTW This is also how git submodule works.

Upvotes: 2

Klas Mellbourn
Klas Mellbourn

Reputation: 44397

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)

Upvotes: 7

Related Questions