Have you ever cleared out an entire directory, left only a couple of tiny text files or scripts behind, and noticed the folder size is still massive? You look inside, see 11 KB of actual files, but Windows properties or your terminal insists the directory is taking up 138 MB.
If you are using Git for version control in that folder, don’t panic! this behavior is completely normal. Here is a breakdown of why this happens and how you can reclaim your disk space.
TLDR; I came across this edge case when I was about to do an important deadline submission for my university assignments , which the application we used to send the zip folder only allowed us to send any files below 100mb capacity!
The Ghost in the Machine: Git History
When you delete a file using standard methods, like right-clicking and hitting Delete, or running rm in your terminal , you are only removing it from your current working directory.Git’s entire purpose is to remember everything that has ever happened in your project.
Because of this:
Every time you add a large file (like a video, image, or heavy dataset) and commit it, Git compresses it and stores it inside a hidden directory called .git/objects.
If you delete that file in a later commit, Git records the deletion, but it keeps the file in its historical database in case you ever need to restore it or look back at old code.
If you enable "Show hidden files" in your operating system, you will likely see a hidden .git folder sitting there, quietly holding onto megabytes of dead history.
How to Fix It and Shrink Your Folder
Depending on whether you actually need your past Git commit history, you have two main options to fix this issue.
Option 1: Start Fresh (The Easiest Route)
If this is a local project or you simply don’t care about preserving your past Git commit logs, the fastest way to shrink the folder is to delete the hidden Git database and start over.
Open your terminal or Command Prompt inside your project folder.
Delete the hidden .git folder using the appropriate command for your OS:
Windows (Command Prompt):rmdir /s /q .git
Mac / Linux:rm -rf .gitReinitialize a brand-new, clean repository:
PS:/project-folder> git init PS:/project-folder> git add . PS:/project-folder> git commit -m "Initial commit with clean files"
Your folder size will instantly drop from 138 MB down to exactly what your current files weigh (~11 KB).
Option 2: Purge the Files from Git History (Keep Your Logs)
If you need to keep your commit history but want Git to completely forget those large, deleted files ever existed, you have to force Git to clear its internal cache and rewrite its history log.
Run these commands in your terminal:
# 1. Force Git to clear out its internal history logs (reflogs) PS:/project-folder> git reflog expire --expire=now --all # 2. Aggressively optimize, prune, and clear the untracked history data PS:/project-folder> git gc --prune=now --aggressive
⚠️ Note: If those large files were committed a long time ago and modified across many different updates, standard git gc might not catch everything. If your folder size doesn't budge after this, you may need to use an advanced history-rewriting tool like git-filter-repo to surgically remove the heavy files from your history completely.
Thank you for reading my new article! Let me know your thoughts down below and hopefully it is helpful for some of you who needed to submit your assignment projects in a flash!
