Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

relocating the .git folder

Tags:

git

I don't think this is possible without a bit of hacking but just throwing it out there.

In Git is it possible to relocate the bulk of the .git folder (/objects i assume) to another location. I am having a problem without my current hard drive filling up with git and i want to be able to move it to a separate hard drive to free up space.

like image 244
Shard Avatar asked Mar 22 '26 08:03

Shard


2 Answers

There are three possibilities I can think of:

  1. The GIT_DIR environment variable tells Git where to look for the repository. The default is .git, obviously, but you can also set it to /some/where/else, if you want.
  2. The GIT_OBJECT_DIR environment variable does the same, but just for the .git/objects subdirectory, not the whole repository.
  3. You can use the file .git/objects/info/alternates or the environment variable $GIT_ALTERNATE_OBJECT_DIRECTORIES to "borrow" objects from another repository.

See the git-repositorylayout(5) manual page for details.

like image 83
Jörg W Mittag Avatar answered Mar 24 '26 15:03

Jörg W Mittag


Git has a command line option called --git-dir. Whenever you run git, use the --git-dir option.

 git --git-dir=a_different_git_directory status

Perhaps you could put that in a batch file or something to make your life easier.

like image 20
Michael Avatar answered Mar 24 '26 15:03

Michael



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!