GIT Repo is massive even after deleting a load of larger files

I have a long standing git repo that ended up with a whole load of irrelevant files in it from another developer that was taking up huge amounts of storage, it was using something silly like 5gb as he had included resource files, there were 5000 PSD files in the repo.

I have remove all those files from the repo and added the folder to gitignore, i also went through and removed a bunch of plugins (wordpress site) and added them using wpackagist instead so they aren't committed to the repo (only the composer.json is).

So after all the clean up, removing cached files from the repo, adding everything to gitignore and then committing everything as a "cleanup" commit, when i come to push up to gitlab it's still adding up to around 5gb and i have no idea why since i've removed all the large files and folders.

Just wondering what i'm missing? It won't even push to the new repo on gitlab as it's just far too big and ends up cutting the connection off.


Solution 1:

Because you still have your Git history, the files are still technically there, even if not on your latest branch.

You can remove all Git history for the repo and have the current state become the initial state:

As seen from: https://stackoverflow.com/a/26000395

  1. Checkout
  • git checkout --orphan latest_branch
  1. Add all the files
  • git add -A
  1. Commit the changes
  • git commit -am "commit message"
  1. Delete the branch
  • git branch -D main
  1. Rename the current branch to main
  • git branch -m main
  1. Finally, force update your repository
  • git push -f origin main

Also see: Make the current commit the only (initial) commit in a Git repository?