Jon Chesterfield Jon Chesterfield - 4 months ago 10
Git Question

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

Answer

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
Comments