How to reduce disk space usage in a large repository?

I have a git repository with about 1 year of development history, and it is already 37GB. How can I minimize the size in a way where I will delete the old history? That is, I only need the history that covers the last 2 months, others can be removed.

  • “make clean” doesn't clean dependencies with Automake?
  • git: why exactly is the claim “git is based on differences between files” wrong?
  • git status shows “\n\n” as an untracked file
  • Windows git: Fatal: TaskCanceledException encountered
  • git rebase strange confliction, there are unexcpected contend
  • How to select git commit ranges with inclusive end points
  • One Solution collect form web for “How to reduce disk space usage in a large repository?”

    The three main options are:

    • removing large files from the history (with, for instance, BFG)
    • split a repo subfolder into its own repo
    • split a repo history (starting with a new repo from HEAD of new repo, keeping the old one for archive).

    On the last point, see “How do I remove the old history from a git repository?”, using a script like this one (with the SHA1 of the commit from 2 months ago, as a parameter)

    git checkout --orphan temp $1
    git commit -m "Truncated history"
    git rebase --onto temp $1 master
    git branch -D temp
    # The following 2 commands are optional - they keep your git repo in good shape.
    git prune --progress # delete all the objects w/o references
    git gc --aggressive # aggressively collect garbage; may take a lot of time on large repos

    Since it rewrites the history, you will need a git push --force.
    Since the OP is pushing to (see discussion), this issue clearly states

    You need to enable the --force option.
    This is done from the Git repository Settings tab. You need to be an ‘Owner’ on the space to see the settings tab.

    Git Baby is a git and github fan, let's start git clone.