Move .git into a different directory than the source it manages
I am not asking how to move a git repository. I want to move the metadata contained within .git to somewhere else on a single machine, without affecting the rest of the world.
The goal is to have
~/gitmetadata/myproject/.git
~/gitmetadata/myproject/.gitignore
~/somecode/myproject/ # No .git here anymore
The purpose of this exercise is to place .git onto persistent storage (ssd) while the working directory holding source / object code etc is on a ram disk. I don't especially want to put the .git on the ramdisk as well, since I'd rather not have to start each reboot by cloning a remote repo.
Ideally I'm looking for a configuration option that I can write into a per-machine configuration file that says "actually, the files are over there".
I can work around this by either having a local repo that I pull from, provided I learn how to configure a git repo to do transparent forwarding, or by hacking up the filesystem unionfs style which will be slow.
Can git put the .git metadata somewhere else?
edit: One of the answers included the phrase "git config core.worktree". Typing this into google found a duplicates which my search did not, 2013, 2009
Move your .git directory to where you wish -lets say, /tmp/back-up-dir Replace the .git directory with a .git file that contains gitdir path.
Eg:
$ cd myProject
$ mv .git /tmp/back-up-dir/.git
$ echo "gitdir: /tmp/back-up-dir/.git" > .git
$ git config core.worktree $PWD
git init:
--separate-git-dir=<git dir>
Instead of initializing the repository as a directory to either $GIT_DIR
or ./.git/, create a text file there containing the path to the actual
repository. This file acts as filesystem-agnostic Git symbolic link to the
repository.
If this is reinitialization, the repository will be moved to the specified
path.
Yes, you can move your .git
folder to permanent storage, and then set the $GIT_DIR
environment variable to point to that location.
Note, however, that you cannot put your .gitignore
files there. They live in the working directory, and they contain paths relative to the directory that they're in. (These typically get checked in, and are part of the repository, anyway.) You can use $GIT_DIR/info/exclude
if you want an out-of-repository mechanism to ignore files.
上一篇: 如何在python中拼合一个嵌套列表?
下一篇: 将.git移动到与其管理的源不同的目录中