You could create your Git repo with:
- the working tree being a current path on the local disk partition
- but the
.git
dir being specified with --git-dir=<path>
or $GIT_DIR
environment variable and referring to a path within your (backed-up) home directory.
The git init
command takes into account the $GIT_DIR
environment variable:
If the $GIT_DIR
environment variable is set then it specifies a path to use instead of ./.git
for the base of the repository.
Alternatively, you can create your repo in your home dir, but add the following git config
:
core.worktree
Set the path to the root of the work tree.
This can be overridden by the GIT_WORK_TREE
environment variable and the --work-tree
command line option.
It can be an absolute path or a relative path to the .git
directory, either specified by --git-dir
or GIT_DIR
, or automatically discovered.
If --git-dir
or GIT_DIR
are specified but none of --work-tree
, GIT_WORK_TREE
and core.worktree
is specified, the current working directory is regarded as the root of the work tree.
Note that this variable is honored even when set in a configuration file in a ".git
" subdirectory of a directory, and its value differs from the latter directory (e.g. "/path/to/.git/config
" has core.worktree
set to "/different/path
"), which is most likely a misconfiguration.
Running git commands in "/path/to
" directory will still use "/different/path
" as the root of the work tree and can cause great confusion to the users.
The OP adds:
Could it be as simple as creating a .git symbolic link in the local partition to the .git directory in the remote NFS partition?
At least, with settings (like git-dir
, or core.worktree
), that allows to achieve the same effect without relying on the OS specific features like symbolic link (which is not available on every OS)
Update 2018 (8 years later): Tom Russell adds in the comments:
It appears that the --separate-git-dir
flag is now used to point to .git/
on the NFS server when initializing the repository on the local workstation (NFS client).
Subsequent behavior is odd, though: Changes committed on the NFS client don't automatically propagate to the server, requiring a git checkout -- <file>
on the server.
I subsequently figured out that a git reset --hard
in the server repo after a commit in the client repo (or vice-versa) is the easiest way to bring a working directory up to date.