Find size of Git repository
Asked Answered
A

8

392

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.

Atheroma answered 18/11, 2011 at 16:3 Comment(1)
H
316

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 Can I fetch a stash from a remote repo into a local branch? also)
  • rerere cache (which can get considerable)
  • reflogs
  • backups (from filter-branch, e.g.) and various other things (intermediate state from rebase, bisect etc.)
Houle answered 18/11, 2011 at 16:6 Comment(8)
Thanks! The first behavior more accurately reflected the total clone size but the second was also pretty close.Atheroma
Note: this answer is out of date. See VonC's answer instead for git versions >= 1.8.3.Astarte
Note also my answer is a ways more complete, which could have it's own merit.Houle
Can you please add what git bundle and git gc actually does? will it create another (unwanted) archive and then measure the size?Rayerayfield
@RameshPareek yes. This is pretty clear because I'm using du to measure the size of that file.Houle
@Houle How does it ans. the OP's Q. He is asking to find size of repo before closing it right? But the above command is for finding size after cloning. Isn't it?Emblaze
@Emblaze Repos exist even before cloning. All I did /not/ do is assume he doesn't have access to a repo. Also, note that my answer is relatively old, and the newer Git versions have better commands available posted in newer answers.Houle
This is the best answer because it shows the REAL size, even after 1.8.3 ver.Purifoy
C
367

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.

Centigram answered 23/4, 2013 at 7:37 Comment(0)
H
316

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 Can I fetch a stash from a remote repo into a local branch? also)
  • rerere cache (which can get considerable)
  • reflogs
  • backups (from filter-branch, e.g.) and various other things (intermediate state from rebase, bisect etc.)
Houle answered 18/11, 2011 at 16:6 Comment(8)
Thanks! The first behavior more accurately reflected the total clone size but the second was also pretty close.Atheroma
Note: this answer is out of date. See VonC's answer instead for git versions >= 1.8.3.Astarte
Note also my answer is a ways more complete, which could have it's own merit.Houle
Can you please add what git bundle and git gc actually does? will it create another (unwanted) archive and then measure the size?Rayerayfield
@RameshPareek yes. This is pretty clear because I'm using du to measure the size of that file.Houle
@Houle How does it ans. the OP's Q. He is asking to find size of repo before closing it right? But the above command is for finding size after cloning. Isn't it?Emblaze
@Emblaze Repos exist even before cloning. All I did /not/ do is assume he doesn't have access to a repo. Also, note that my answer is relatively old, and the newer Git versions have better commands available posted in newer answers.Houle
This is the best answer because it shows the REAL size, even after 1.8.3 ver.Purifoy
C
140

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.

Creepy answered 18/11, 2011 at 16:23 Comment(4)
In my experience, git count-objects -v works when git-count-objects -v does not (because it is not in my PATH).Magel
@psihodelia It seems you might have to run git gc before running git count-objects -v because your repository may not have been packed yet. See the first answer here for evidence: #3533240Creepy
You can use grep to get only the desired line: git count-objects -vH | grep 'size-pack'. The H is to show it in human readable format, as @Centigram said in his answer.Sourdough
git count-objects --help: size-pack: disk space consumed by the packs, in KiB (unless -H is specified)Gilbertogilbertson
I
23

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.

Ichthyosis answered 19/9, 2018 at 4:1 Comment(6)
This is nice because it shows more information than just the total cloning size. One thing it doesn't show that I'd still like to know is how big the ZIP will be if downloaded (it doesn't contain all the commits).Retro
@IndrajeetGour: you need to install from github.com/github/git-sizer/#getting-started. Downloads are at github.com/github/git-sizer/releases.Ichthyosis
Would the @downvoter care to explain his reasoning, or not?Ichthyosis
If you are on macos, you can install it using homebrew.Tamica
Thanks for the tool recommendation, but I think the "Total size of files" represents the size of the biggest checkout, not the entire size of the repo including the history. I mean if you scroll up a little, you will notice that the Blobs alone are 55.8 GiB. You need to add the sizes of the commits, trees, blobs, etc. to get the total.Jodhpur
Adding to Jame's note, brew install git-sizerSpandex
D
10

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

Deportee answered 10/7, 2020 at 18:4 Comment(0)
T
4

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
Tabatha answered 5/10, 2017 at 10:4 Comment(0)
L
1

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.

Laclair answered 1/6, 2019 at 3:6 Comment(3)
Your commands gives me 29941282 but du -sb .git/ says 19215458 .git/, can you explain the difference ?Selenography
@SebMa: Doesn't git compress things internally? (And encode identical files only once?)Laclair
@Selenography The .git directory contains enough data to reconstruct all files for any branch/tag/revision. The du value definitely won't be a match, but assuming that most files are text, compression would definitely explain it.Bricabrac
P
0

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.

Prudential answered 14/10, 2019 at 20:14 Comment(3)
They are in different units (GB x GiB). By the way 1.71 GB = 1.84 GiB, just converting and not caring about rounds.Cowen
Sorry, I mixed them up when typing, the correct relation: 1.71 GiB = 1.84 GBCowen
the repo filesize label relies on the github api response, that can be incomplete as of githubs statement. See updated comment at https://mcmap.net/q/73235/-how-can-i-see-the-size-of-a-github-repository-before-cloning-it concerning shared repository objectsIndisputable

© 2022 - 2024 — McMap. All rights reserved.