DEV Community

Cover image for Why Is my 11 KB Project Folder Saying It’s 138 MB? (And How to Fix It)
Raziq Din
Raziq Din

Posted on

Why Is my 11 KB Project Folder Saying It’s 138 MB? (And How to Fix It)

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:

  1. 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.

  2. 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.
 

  1. Open your terminal or Command Prompt inside your project folder.

  2. Delete the hidden .git folder using the appropriate command for your OS:
    Windows (Command Prompt): rmdir /s /q .git
    Mac / Linux: rm -rf .git

  3. Reinitialize 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"
Enter fullscreen mode Exit fullscreen mode

 
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
Enter fullscreen mode Exit fullscreen mode

 
⚠️ 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!

Top comments (0)