title: How to reduce git repo size on Bitbucket?
body: <p><strong>Summary of my problem:</strong> One of my private repositories on Bitbucket suddenly more than doubled in size after I pushed an addition of a few hundred bytes to two existing files. The repo is now over 2GB, which has caused Bitbucket to put it into read-only mode. Because it is in read-only mode, I cannot push changes that would reduce the repo size. (Catch 22.)</p>
  
  <p><strong>Details:</strong> My company recently began hosting git repositories on Bitbucket. One of the repositories I am in charge of had a size of about 973MB, which was uncomfortably close to the 1GB soft limit. To reduce the repo size, I followed the instructions in the Bitbucket documentation article <a href="https://confluence.atlassian.com/display/BITBUCKET/Split+a+repository+in+two" rel="noreferrer">Split a repository in two</a> and moved about 450MB worth of documentation and online help files into their own private repo. I then followed the instructions in the Bitbucket documentation articles <a href="https://confluence.atlassian.com/display/BITBUCKET/Reduce+repository+size" rel="noreferrer">Reduce repository size</a> and <a href="https://confluence.atlassian.com/display/BITBUCKET/Maintaining+a+Git+Repository" rel="noreferrer">Maintaining a git repository</a>, specifically:</p>
  
  <p><code>git count-objects -vH</code> showed me a size-pack of about 973MB.</p>
  
  <p>I ran <code>git filter-branch --index-filter 'git rm --cached --ignore-unmatch doc' HEAD</code> to remove the doc directory (which is the content I'd moved to the new repo).</p>
  
  <p>I ran the following commands to expire reference and prune:</p>
  
  <pre><code>git for-each-ref --format="%(refname)" refs/original/ | xargs -n 1 git update-ref -d
  git reflog expire --expire=now --all
  git gc --prune=now
  </code></pre>
  
  <p><code>git count-objects -vH</code> then showed me a size-pack of 881.1 MiB and <code>du -sh .git/objects</code> returned 882M. I was disappointed that moving over 450MB reduce the repo size by less than 90MB, but pushed the changes to Bitbucket nevertheless:</p>
  
  <pre><code>git push --all --force
  git push --tags --force
  </code></pre>
  
  <p>The settings page for the Bitbucket copy of the repo continued to show a size of 973MB. I logged out, refreshed the browser, logged back in, but that didn't help -- the repo size remained at 973MB.</p>
  
  <p>This morning (three days after the changes described above) I made a couple of minor additions to two existing files which increased the files' sizes by a total of less than 1KB, added and commited them to my local repo, then pushed the change to Bitbucket. A few minutes later I took a look at the Bitbucket page for the repo and saw a red warning banner informing me "This repo is over the 2 GB limit and is in read-only mode." The settings page now says the repo has a size of 2.3 GB.</p>
  
  <p>The push of a few hundred bytes added to two files was definitely the only activity to occur on the remote repo in the last three days, according to Bitbucket. That push may not have been the cause of the repo more than doubling in size, but the two events were closely correlated in time.</p>
  
  <p><code>git reflog show</code> returns nothing.</p>
  
  <p>Cloning a new copy into an alternate directory, then running git count-objects give me a size-pack of 881.29 MiB.</p>
  
  <p>The local repository is on a CentOS 6.5 system. git version is 1.8.5.3.</p>
  
  <p><strong>Questions</strong></p>
  
  <ol>
  <li>Why did moving 450MB of files out of the repo only reduce the size of my local repo by 90MB?</li>
  <li>Why did even that modest reduction not get pushed to the remote repo on Bitbucket?</li>
  <li>How on Earth did the remote repo size jump from 973MB to 2.3GB?</li>
  <li>How do I fix it? I cannot push to the remote repo even with the --force flag. Any push gets me the error message "conq: repository is in read only mode (over 2 GB size limit).
  fatal: Could not read from remote repository."</li>
  </ol>