Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8707495
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:53:02+00:00 2026-06-13T03:53:02+00:00

Way back in the past I accidentally committed a large number of Java artifacts

  • 0

Way back in the past I accidentally committed a large number of Java artifacts (.war, .jar and .class) into my GitHub repo. This resulted in a huge bloat in size to about 100Mb. I didn’t notice until many commits and branch merges later.

Fortunately, there is a lot of info out there about this and so after trawling endlessly through StackOverflow, GitHub and Git documentation (thanks everyone!) I finally managed to put the following script together:

#!/bin/bash          
echo "Removing history for *.war, *.jar, *.class files"

echo "Starting size"
git count-objects -v

echo "Removing history for *.war, *.jar, *.class files"
git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch *.war' --prune-empty --tag-name-filter cat -- --all
git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch *.jar' --prune-empty --tag-name-filter cat -- --all
git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch *.class' --prune-empty --tag-name-filter cat -- --all

echo "Purging refs and garbage collection"
# Purge the backups 
rm -Rf .git/refs/original

# Force reflog to expire now (not in the default 30 days)
git reflog expire --expire=now --all

# Prune
git gc --prune=now

# Aggressive garbage collection
git gc --aggressive --prune=now

echo 
echo "Ending size (size-pack shows new size in Kb)"
git count-objects -v

# Can't do this in the script - it needs a human to be sure
echo
echo "Now use this command to force the changes into your remote repo (origin)"
echo 
echo git push --all origin --force

This worked perfectly locally, my 100Mb repo dropped to about 2Mb. I then used the

git push --all origin --force

command to overwrite all branches in the GitHub repo with my local changes. All went well. To check everything I deleted my local repo and cloned from GitHub. This should have been 2Mb, but was again 100Mb.

So, after all that rambling, where have I gone wrong? How can I force GitHub to use my local repo with its purged history?

Edits for further information

The GitHub repo can’t be deleted since it has a lot of additional information surrounding it (issues, wiki, watches etc). Performing this script against an empty scratch repo works fine – the cloned repo is 2Mb.

The problem remains as to why it doesn’t work with the main repo.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T03:53:03+00:00Added an answer on June 13, 2026 at 3:53 am

    It was all because of a fork

    It turns out that if someone forks your repo on GitHub, then they retain links and references to entries within it. Consequently, your purge won’t work unless everyone who is holding a fork also runs the script on their repo.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way to convert from toString back to the object in Java?
I'm a R user from way back but struggling to get my head around
I have done Objective-C way back when, and have recently (i.e. just now) read
Can anyone please suggest a way to replace back-slash '\' with slash '/' in
What could be the best preferable way of returning back a modified list grabbed
Using .NET's Office interop libraries, does anybody know the best way to convert back
Is there a way I can piggy back sessions to know if the user
Is there any robust way of implementing Cassandra back end to a web application
Is there's any way how to reset styles back to what's in my CSS?
Is there a way to disable the browser's back button after loggin out? I've

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.