Find size of Git repository

GitFilesize

Git Problem Overview


What's a simple way to find the size of my Git repository?

And I don't mean du -h on the root directory of my repository. I have a lot of ignored files, so that size would be different from my total repository size. I essentially want to know how much data would be transferred upon cloning my repository.

Git Solutions


Solution 1 - Git

Note that, since git 1.8.3 (April, 22d 2013):

> "git count-objects" learned "--human-readable" aka "-H" option to show various large numbers in Ki/Mi/GiB scaled as necessary.

That could be combined with the -v option mentioned by Jack Morrison in his answer.

git gc
git count-objects -vH

(git gc is important, as mentioned by A-B-B's answer)

Plus (still git 1.8.3), the output is more complete:

> "git count-objects -v" learned to report leftover temporary packfiles and other garbage in the object store.

Solution 2 - Git

> UPDATE git 1.8.3 introduced a more efficient way to get a rough size: git count-objects -vH (see answer by @VonC)

For different ideas of "complete size" you could use:

git bundle create tmp.bundle --all
du -sh tmp.bundle

Close (but not exact:)

git gc
du -sh .git/

With the latter, you would also be counting:

  • hooks
  • config (remotes, push branches, settings (whitespace, merge, aliases, user details etc.)
  • stashes (see https://stackoverflow.com/questions/2248680/#5257371 also)
  • rerere cache (which can get considerable)
  • reflogs
  • backups (from filter-branch, e.g.) and various other things (intermediate state from rebase, bisect etc.)

Solution 3 - Git

The git command

git count-objects -v

will give you a good estimate of the git repository's size. Without the -v flag, it only tells you the size of your unpacked files. This command may not be in your $PATH, you may have to track it down (on Ubuntu I found it in /usr/lib/git-core/, for instance).

From the Git man-page:

> -v, --verbose

> In addition to the number of loose objects and disk space consumed, it reports the number of in-pack objects, number of packs, disk space consumed by those packs, and number of objects that can be removed by running git prune-packed.

Your output will look similar to the following:

count: 1910
size: 19764
in-pack: 41814
packs: 3
size-pack: 1066963
prune-packable: 1
garbage: 0

The line you're looking for is size-pack. That is the size of all the packed commit objects, or the smallest possible size for the new cloned repository.

Solution 4 - Git

For more details, you could use git-sizer. In the --verbose setting, the example output is (below). The Total size of files line only counts the size of files in the biggest commit. You would need to sum the size values.

> $ git-sizer --verbose > Processing blobs: 1652370 > Processing trees: 3396199 > Processing commits: 722647 > Matching commits to trees: 722647 > Processing annotated tags: 534 > Processing references: 539 > | Name | Value | Level of concern | > | ---------------------------- | --------- | ------------------------------ | > | Overall repository size | | | > | * Commits | | | > | * Count | 723 k | * | > | * Total size | 525 MiB | ** | > | * Trees | | | > | * Count | 3.40 M | ** | > | * Total size | 9.00 GiB | **** | > | * Total tree entries | 264 M | ***** | > | * Blobs | | | > | * Count | 1.65 M | * | > | * Total size | 55.8 GiB | ***** | > | * Annotated tags | | | > | * Count | 534 | | > | * References | | | > | * Count | 539 | | > | | | | > | Biggest objects | | | > | * Commits | | | > | * Maximum size 1 | 72.7 KiB | * | > | * Maximum parents 2 | 66 | ****** | > | * Trees | | | > | * Maximum entries [3] | 1.68 k | * | > | * Blobs | | | > | * Maximum size [4] | 13.5 MiB | * | > | | | | > | History structure | | | > | * Maximum history depth | 136 k | | > | * Maximum tag depth [5] | 1 | | > | | | | > | Biggest checkouts | | | > | * Number of directories [6] | 4.38 k | ** | > | * Maximum path depth [7] | 13 | * | > | * Maximum path length [8] | 134 B | * | > | * Number of files [9] | 62.3 k | * | > | * Total size of files [9] | 747 MiB | | > | * Number of symlinks [10] | 40 | | > | * Number of submodules | 0 | | >
> 1 91cc53b0c78596a73fa708cceb7313e7168bb146 > 2 2cde51fbd0f310c8a2c5f977e665c0ac3945b46d > [3] 4f86eed5893207aca2c2da86b35b38f2e1ec1fc8 (refs/heads/master:arch/arm/boot/dts) > [4] a02b6794337286bc12c907c33d5d75537c240bd0 (refs/heads/master:drivers/gpu/drm/amd/include/asic_reg/vega10/NBIO/nbio_6_1_sh_mask.h) > [5] 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c (refs/tags/v2.6.11) > [6] 1459754b9d9acc2ffac8525bed6691e15913c6e2 (589b754df3f37ca0a1f96fccde7f91c59266f38a^{tree}) > [7] 78a269635e76ed927e17d7883f2d90313570fdbc (dae09011115133666e47c35673c0564b0a702db7^{tree}) > [8] ce5f2e31d3bdc1186041fdfd27a5ac96e728f2c5 (refs/heads/master^{tree}) > [9] 532bdadc08402b7a72a4b45a2e02e5c710b7d626 (e9ef1fe312b533592e39cddc1327463c30b0ed8d^{tree}) > [10] f29a5ea76884ac37e1197bef1941f62fda3f7b99 (f5308d1b83eba20e69df5e0926ba7257c8dd9074^{tree})

BTW: if you would like to minimize the clone size, you can use the --depth 1 parameter of git clone.

Solution 5 - Git

This answer applies if you have pushed your git repository to github.

You can easily find the size of each of your repository in your Accounts settings

Solution 6 - Git

If you use git LFS, git count-objects does not count your binaries, but only the pointers to them.

If your LFS files are managed by Artifactorys, you should use the REST API:

  • Get the www.jfrog.com API from any search engine
  • Look at Get Storage Summary Info

Solution 7 - Git

I think this gives you the total list of all files in the repo history:

git rev-list --objects --all | git cat-file --batch-check="%(objectsize) %(rest)" | cut -d" " -f1 | paste -s -d + - | bc

You can replace --all with a treeish (HEAD, origin/master, etc.) to calculate the size of a branch.

Solution 8 - Git

If the repository is on GitHub, you can use the open source Android app Octodroid which displays the size of the repository by default.

For example, with the mptcp repository:

Size of multipath TCP repository on Octodroid

Size of the repository while cloning

Disclaimer: I didn't create Octodroid.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionmschallertView Question on Stackoverflow
Solution 1 - GitVonCView Answer on Stackoverflow
Solution 2 - GitseheView Answer on Stackoverflow
Solution 3 - GitJack MorrisonView Answer on Stackoverflow
Solution 4 - Gitserv-incView Answer on Stackoverflow
Solution 5 - GitVivek AggarwalView Answer on Stackoverflow
Solution 6 - GitelikeView Answer on Stackoverflow
Solution 7 - Gituser541686View Answer on Stackoverflow
Solution 8 - GitRMPRView Answer on Stackoverflow