I have my source code and .git folder on a small fast ssd, I would like to have the .git directory on my second bigger slower hdd and keep my working code on my fast smaller
You can symlink (or use junction points) the .git
dir to a different location:
$ cd my/project
$ mv .git /over/here/.git
ln -s /over/here/.git .
And the repository will work fine.
Or you can replace the .git
folder with a file that tells git where the .git
folder really is. This is exactly how git submodules are setup by default in version 1.7.8 or later.
The steps to re-configure an existing checkout are:
.git
containing: gitdir: path/to/.git
core.worktree
to point at the working copyAs a script that would be:
$ cd my/project
$ mv .git /tmp/.git
$ echo "gitdir: /tmp/.git" > .git
$ git config core.worktree $PWD
Easily create junctions on Windows using junction.exe from Microsoft.
> junction.exe c:\fast-ssd\proj\.git d:\slow-hdd\proj\.git
The --separate-git-dir
method is exactly the same as the gitdir
approach.
After running
$ git init --separate-git-dir=[path to directory for .git data]
what happens is that a .git
file is created in the local directory with the following content:
gitdir: [path to directory for .git data]
It is possible to have a Git repository directory in a different location than the root of your working copy, but I'm not sure if it works across drives.
You can set the repo directory to be placed in a different directory while cloning with the --separate-git-dir flag:
$ git clone --separate-git-dir=<path to directory for repo> \
<remote url> <path for working copy>
For a repo that's already been cloned, you might be able to set a different path for the repo and/or working copy with the --git-dir=<path> and --work-tree=<path> flags for git.
You might also want to check out the core.worktree configuration.
Actually, you can just run
$ git init --separate-git-dir=[path to directory for .git data]
git init is safe to be used inside an already cloned repository
Running git init in an existing repository is safe. It will not overwrite things that are already there. The primary reason for rerunning git init is to pick up newly added templates (or to move the repository to another place if --separate-git-dir is given).
Reference to Git manual page