Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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 ssd, is it possible? how? thanks.

I guess my local working copy .git directory will grow as time goes (with the new versions) and so it make sens to have it on my bigger local hdd. The working copy doesn't grow as fast so it makes sens on the ssd as it can compile faster.

The other interesting bonus is I will then have the source code (working code and .git repo) on 2 diff drives which is more protection for a laptop....

I'm using windows

like image 241
wily Avatar asked Jul 28 '13 22:07

wily


People also ask

Can you move a .Git folder?

Essentially what you need to do is move the . git folder to the folder you want to be the root folder. These are the steps I took in the command line (remember I am moving my . git one folder inwards - you will need to adjust the commands to your needs).

Can I store the .Git folder outside the files I want tracked?

You can keep a selection of the files you want git to track using the . gitignore file. If you'd add * and ! myfiles to it, only that directory will be tracked.

Is it safe to copy .Git folder?

Nope, it'll be fine to just copy the repo's root directory. Just make sure you get any invisible files, too, especially the . git directory (in the project's root) which contains all the config information for the repo. Save this answer.


1 Answers

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 
like image 191
AD7six Avatar answered Oct 30 '22 21:10

AD7six