1

I have a git repo which has branches like branch-a, branch-b, branch-c. Now, in branch-b I have mistakenly uploaded a big file (200mb). Now the overall repo has exceeded to 230mb. Whenever I do git clone, I am downloading 230mb when I only require 30mb of data. I also deleted this branch both locally and in remote. This branch has not merged with master, and its commits are of no use.

How can I reduce my repo size as if this branch had never existed? I do not want the commits to be rewritten. To delete the branch I have followed:

git checkout master
git branch -D branch-b
git push origin --delete branch-b

I am new to git so, if I could get exact steps to do this would be very helpful, I am scared of messing up the remote.

Sourav
  • 129
  • 12
  • 1
    *How can I reduce my repo size as if this branch had never existed? I do not want the commits to be rewritten.* You may not have a choice: if the file exists in some commit that is [reachable](http://think-like-a-git.net/), you must rewrite history so that this is no longer the case. After that, you wait: Git will eventually "garbage collect" the unwanted commits and the repository will shrink. Cloning will generally go faster right away as clones won't pick up any unreachable commits. – torek Mar 09 '21 at 07:07
  • Thanks @torek that is relieving. When will git perform garbage collection? – Sourav Mar 09 '21 at 07:56
  • 1
    The time of a future GC is not predictable. You can force one immediately if it's important (see @VonC's answer) but you'll need to expire any reflog entries that refer to the commit, too. The reflogs are a safety feature that let you get commits back if you want them. Reflog entries themselves eventually expire, so this "get commits back" has a time limit, but the actual expiration is merely an "at least" (at least 30 days, at least 90 days). – torek Mar 09 '21 at 19:02

1 Answers1

2

On your local repo, you can try (as I detailed here)

git gc
git repack -Ad      # kills in-pack garbage
git prune           # kills loose garbage

You can also, as commented, clone the remote repository to check if the size has changed.

In both case (local gc, or clone), apply the tool github/git-sizer to check what element is still taking space in your repository.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250