Save git files to another folder

How to configure git to track files in ~/a folder but save .git folder in ~/b folder?

Also, to continue this (huge) step, can I save the .git folder on another server and run the git commands from server a to check git st , for example, on server b

Basically, I would like to use git in a specific folder without saving the .git directory in the same folder. and for my second question above I would like to take this step further without even saving the .git directory on the same server

Thanks!

+6
source share
2 answers

Set the GIT_DIR environment GIT_DIR .

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 --git-dir for all git commands:

 git --gir-dir=~/b status 

See this article about git environment variables

About placing the git repository directory on another server: well, if you installed the file system from this server and have the appropriate permissions, this should work fine. The git commands that work in your local directory are mainly about accessing the file system, so they work as long as it works.

(To clarify: above, I assume that ~/b is a git directory, if .git is a ~/b subdirectory, you should use ~/b/.git instead)

+7
source

Alternative way: you can specify the real path to the .git folder in the file and redirect operations to it.

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

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

Then you can have a work tree in A that uses the .git folder in B.

By the way. This also works git submodule .

+2
source

Source: https://habr.com/ru/post/948424/


All Articles