How to detach the local git repository from its working directory?

前端 未结 2 2033
猫巷女王i
猫巷女王i 2021-01-23 18:16

Is this feasible?

I would like to have the .git directory on another drive than the checkout directory. I could not find a way to detach both.

The r

相关标签:
2条回答
  • 2021-01-23 18:30

    I'd really suggest keeping your entire repo on your preferred drive. You can then put a bare repo on the beyond-your-control drive, and push to it. This is the best way to minimize your interactions with the bad storage.

    If for some reason you must split a repo across drives, why not just create the repo on one drive, move the .git directory to the other drive, then symlink .git in your repo to the relocated .git directory.

    0 讨论(0)
  • 2021-01-23 18:34

    You can set 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.

    If setting an environment variable is infeasible for any reason, you can use the --git-dir option with any git command:

    --git-dir=<path>
    

    Set the path to the repository. This can also be controlled by setting the GIT_DIR environment variable. It can be an absolute path or relative path to current working directory.

    0 讨论(0)
提交回复
热议问题