Skip to content

Instantly share code, notes, and snippets.

@minlaxz
Last active October 26, 2021 05:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save minlaxz/006102cc14f1519cd0284ffbedf2db1c to your computer and use it in GitHub Desktop.
Save minlaxz/006102cc14f1519cd0284ffbedf2db1c to your computer and use it in GitHub Desktop.
Cleaning up a git repo for reducing the repository size

Check git repo size : git count-objects -v

First checkout to the commit, which you want to make as the initial commit. Then run the following commands :

git checkout --orphan temp_branch
git add -A
git commit -am "Initial commit message"
git branch -D main
git branch -m main
git push -f origin main
git gc — aggressive — prune=all # remove the old files

The above commands will force fully push the current source code to main branch as the first command. Note : You should delete all other branches and tags, because it may still contain the old history.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment