0

My local GIT repository became very big and I'm trying to free some hard drive space. I deleted all my old branches and left only the last one. In order to delete branches from my repository, I used the command

git branch -d [my branch name]

The problem is that when I check the repository space usage, it still uses the same amount. Running the garbage collector

git gc

after branches deletion didn't help.

The biggest git repository file is a .pack file inside the .git/objects/pack folder, it takes about 750MB, while the latest branch takes 112MB.

EDIT: I also tried all the

git reflog expire --all --expire=now
git gc --prune=now --aggressive

Neither helped.

Nir
  • 1,836
  • 23
  • 26
  • possible duplicate of [Reduce git repository size](http://stackoverflow.com/questions/2116778/reduce-git-repository-size) – jub0bs Jan 27 '15 at 13:57
  • 2
    The repository also contains the history and that includes any past version of all the files present in the branch you want to keep but also the files that were added then deleted in commits that are reachable from your branch. – axiac Jan 27 '15 at 14:02
  • Have you tried `git gc --aggressive`? Depending on how old your branch is, it might not be autopruned, I believe default is 2 weeks? You could `git gc --aggressive --prune=now`. – Andy Jan 27 '15 at 14:08
  • 1
    What do you mean by "the latest branch takes 112MB"?. How did you determine this? – Joseph K. Strauss Jan 27 '15 at 16:04
  • branch takes 112MB means that this is the size of the files which should be uploaded to GIT (the working directory size) – Nir Jan 28 '15 at 07:00
  • git objects are not necessarily connected to branches. Branches are extremely lightweight in git and have nothing much to do with the /objects/pack folder. Perhaps what you're really looking for is a *shallow clone*? – deceze Jan 28 '15 at 07:42
  • I find it hard to believe that the size of a repository with only one branch of ~100MB will be ~700MB. I'm looking for a way to reduce the size of my repository, how is the shallow copy going to help me? – Nir Jan 28 '15 at 07:54
  • @Nir, The repository contains every commit in every branch. If `git gc` does not remove anything, then every commit is reachable from at least one branch. If you have lots of commits, the repository size will increase. Also changes to binary files increase the repository size, because `git` does not store diffs of binary files but just adds a new version (while still keeping the old version). – Arjan Jan 28 '15 at 21:25
  • Maybe have a look at https://stackoverflow.com/questions/3765234/listing-and-deleting-git-commits-that-are-under-no-branch-dangling – Picaud Vincent Dec 08 '17 at 22:07

1 Answers1

1

If you want to delete your remote branch as of v1.7.0, use this command:

git push origin --delete the_remote_branch

Source https://makandracards.com/makandra/621-git-delete-a-branch-local-or-remote

user8128167
  • 6,929
  • 6
  • 66
  • 79