Let's say I have a git
repo on a limited disk partition (say, a thumbdrive).
Let's say that my last push to that repo failed because the current partition got fully filled.
Let's say I try to reclaim some space with git gc
; then git gc
too will fail with:
$ git gc --prune=now
fatal: failed to write ref-pack file: No space left on device
error: failed to run pack-refs
Now, on the same machine, I have another partition, which has plenty of space; I'm aware that I could clone this repo there, and run gc
there, and then copy back/ write over the repo from the another partition to the first partition.
But I was wondering: instead, is there a way, I could instruct git
to use "another partition" for whatever temporary files it needs to write, while I call git gc
within the repo on the original partition - with the result that after the operation is complete, git
would have deleted the temporary files on the "another partition"; and it would have modified/deleted/added all necessary files in the "original partition" repo (effecting the space reclamation, if it is possible)?
The only option would be to move the .git
directory somewhere else, and then use the --git-dir
option to use that location instead of automatically figuring it out from the current working directory. Apart from that, no, Git won’t be able to temporarily use a different drive.
And if you think about it, the risk of data corruption is far too large to allow Git to compress objects from the database on another drive first, then delete the source objects before finally moving the compressed data back.
So I’d say that this is an edge use-case nobody usually encounters. And today’s thumb drives are large enough that this won’t be a problem that easily too.