“Fun” with Git: How to ignore locally deleted files (in git status) if you’re running out of hard drive space

Oh god I wasted hours on this probably

I have a huge 3 GB git repository that the class I am grading for, uses to track all the student submissions and our grading. My hard drive is constantly teetering below 1 GB of free space so I started having git pull’s fail due to lack of hard drive space (and it’s a PAIN to recover from that issue when half the files are around and half aren’t).

I naturally tried removing the files locally. This does work if I am religious about only using git add -u . in the specific folder (HW0/my_name) that I was working in.

However I rely in constantly looking at git status and it was totally unusable since it would just have 100s of lines of “deleted: “.

After trying out various combinations of .gitignore, git update-index --skip-worktree, git update-index --assume-unchanged -- graders/HW5/ etc., sparse-checkout, .git/info/exclude, etc. The solution is just a single line (but one that may have to be run repeatedly):

rm -rf HW1 HW2 HW3
git ls-files --deleted -z | git update-index --assume-unchanged -z --stdin

This ignores ALL files listed as “deleted” under “git status” prior to running the above line.

Hurray!

Thanks to: https://stackoverflow.com/questions/4589333/git-ignore-locally-deleted-folder

Side note: I bought myself a 2 TB SSD and hopefully that should alleviate some of this, eventually, when I get around to all of the time consuming exporting files from the existing hard drive etc. Hopefully it goes smoothly, wish me luck!

projects blog (nouyang)

Close Bitnami banner
Bitnami