Git repository size issue


At the company where I work, I was using Git to save a system, where three people are using it.

After accidentally uploading a folder of images, doing a git pull became absurd as the downloaded data is almost 1.6GB.

We later remove this image folder via the .gitignore file. However, even after this change, the repository is still very large.

I have a few questions to ask about this:

  • How to reduce the size of a Git repository (when a crash like the one above occurs)?

  • Is there any way to bring in a git pull or a git fetch , ignoring some files like images and/or videos (via parameters or something)?

  • Why, even after deleting the large files and adding them to .gitignore , is Git still huge? Are the ignored (previously added) part of the history?

  • And if "yes" to history, is there any way to delete these junk files from history?


Probably what you want is to rewrite the history of your repository, which can be problematic if you don't know what you're doing (I don't know :P). this is done with filter-branch . An example:

git filter-branch --tree-filter 'rm -rf path/file' HEAD

You may need adaptations, according to your needs, read the documentation for this.

It is also possible to delete a commit and do a rebase but I think it would be more complicated.

Scroll to Top