Why Your GitHub Repository Size Keeps Increasing (And How to Fix It)

Why Your GitHub Repository Size Keeps Increasing (And How to Fix It)

Many developers get confused when their GitHub repository size becomes much larger than the actual project folder. A project may only be 1 GB locally, but the GitHub repository size can grow to 4–5 GB.

This can feel like a mistake but it’s actually how Git is designed to work. 

In this blog, we’ll break down why this happens and how to clean up your repository to reduce space. 

Why Git Repositories Grow Over Time 

Git doesn’t just store your current files, it stores the entire history of your project. 

1. Git Stores Everything (Even Deleted Files) 

Every time you: 

  • Add a file 
  • Modify a file 
  • Delete a file 

Git keeps a record of it. 

Even if you delete a large file later, it still exists in older commits. 

2. Large Files Cause Major Growth 

If you’ve committed files like: 

  • .zip, .tar 
  • Images/videos 
  • Build files (.apk, .exe) 
  • Logs or backups 

These files stay in the repository history forever unless explicitly removed. 

3. Repeated Changes Increase Size 

If a large file is updated multiple times: 

  • Git stores multiple versions internally 
  • This significantly increases repository size over time 

Real-World Example 

Item Size 
Current project files 1 GB 
Git repository size 4–5 GB 

This difference is caused by historical data accumulation. 

How to Reduce Git Repository Size 

Cleaning a Git repository requires removing unnecessary files from both: 

  1. Current tracking 
  2. Repository history 

Step 1: Stop Tracking Unnecessary Files 

Remove files from Git tracking: 

git rm -r –cached node_modules 

git rm -r –cached storage/logs 

Then update your .gitignore: 

node_modules/ 

storage/logs/ 

*.zip 

*.tar 

.env 

Step 2: Remove Files from Git History 

Just deleting files is not enough, you must remove them from history. 

Option 1: Using git-filter-repo (Recommended) 

pip install git-filter-repo 

git filter-repo –path path/to/large-file –invert-paths 

Option 2: Using BFG Repo Cleaner 

java -jar bfg.jar –delete-files ‘*.zip’ 

This is faster and easier for large repositories. 

Step 3: Run Git Garbage Collection 

git gc –prune=now –aggressive 

This permanently removes unused data. 

Step 4: Force Push Clean Repository 

Warning: This rewrites Git history 

git push origin –force –all 

Make sure your team is aware before doing this. 

Best Practices to Prevent Future Issues 

  • Always configure .gitignore properly 
  • Avoid committing: 
  • node_modules/ 
  • logs 
  • compiled files 
  • Use Git Large File Storage for large files 
  • Regularly check repo size: 

git count-objects -vH 

Pro Tip 

If your repository is already too large: 

  • Create a new clean repository 
  • Push only the latest code 
  • Archive the old repository 

Conclusion 

Git repositories grow because they preserve history, not just your current code. 

That’s why: 

A 1 GB project can become a 5 GB repository 

The only way to truly reduce size is by: 

  • Removing unnecessary files 
  • Cleaning history 
  • Following best practices going forward 

Keeping your repository clean ensures: 

  • Faster cloning 
  • Better performance 
  • Easier collaboration 

Author

  • Nithin is a skilled developer specializing in full-stack architecture and the deployment of scalable, multi-tenant platforms. With a focus on building robust, AWS-based solutions, he excels at bridging the gap between complex backend systems and intuitive user experiences. Currently, his professional interests lie in optimizing system performance through AI-driven workflows and developing data-driven strategies that address real-world business needs. Beyond technical execution, he is dedicated to professional mentoring and career counseling, helping emerging IT talent navigate the path from graduation to industry-grade development.

Contact us