tags:

views:

241

answers:

3

My home directory is in a remotely-mounted NFS partition on a file-server and is routinely backed-up. I would like to have my project's git repository be under my home directory (so that it's backed-up) but I would like my working-tree to be in a local disk partition of my workstation (so that building is fast). The local disk partition isn't backed-up.

Any ideas on how to do this? I know that I can clone the NFS repository and push to it, but that seems like unnecessary overkill.

Could it be as simple as creating a .git symbolic link in the local partition to the .git directory in the remote NFS partition?

+3  A: 

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)

VonC
@Bombe: "wording improved" indeed, thank you ;) (improvement done in the true spirit of http://meta.stackoverflow.com/questions/38242/full-time-dedicated-editors-on-so/38244#38244)
VonC
@VonC could the git-dir alternative you posted, be a solution to distribute multimedia (binary) content using git over to remote Android devices where I can't install Git?
microspino
@microspino: I don't have experience in this kind of environment, but this is certainly worth a try.
VonC
A: 

Create your repo in your home directory as usual, then on your fast local disk, use the script git-new-workdir (on my box, under /usr/share/doc/git-core/contrib/workdir). It's not a part of the git core; it's a contributed script but your distro's git package may have installed it. Usage is:

git-new-workdir <repository> <new_workdir>

This will create a new working directory that is symlinked to your original repository.

Wayne Conrad
A: 

Not sure what you mean by overkill, but my suggestion would be to go ahead and have a clone in NFS and push to it.

You can set up a post-commit hook that does a git push --mirror my-nfs-thing and not have to even think about it.

Most importantly, you'll always have fast, reliable access to the repository data (without the fear of losing data to system failures, etc...).

Dustin