Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Move .git into a different directory than the source it manages

Tags:

git

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

like image 651
Jon Chesterfield Avatar asked Nov 16 '25 02:11

Jon Chesterfield


1 Answers

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
like image 109
Niranjan Gattupalli Avatar answered Nov 17 '25 21:11

Niranjan Gattupalli



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!