Git - Moving the .git directory to another drive, keep the source code where it is

前端 未结 4 1395
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-23 15:02

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

4条回答
  •  难免孤独
    2020-12-23 15:18

    Yes you can

    Symlinks

    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.

    gitdir:

    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:

    1. move the .git dir to where it needs to be
    2. replace it with a file .git containing: gitdir: path/to/.git
    3. define core.worktree to point at the working copy

    As a script that would be:

    $ cd my/project
    $ mv .git /tmp/.git
    $ echo "gitdir: /tmp/.git" > .git
    $ git config core.worktree $PWD
    

    Junctions on Windows

    Easily create junctions on Windows using junction.exe from Microsoft.

    > junction.exe c:\fast-ssd\proj\.git d:\slow-hdd\proj\.git
    

提交回复
热议问题