384

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
mschallert
  • 4,129
  • 2
  • 17
  • 10
  • 2
    [See the size of a github repo before cloning it ?](https://stackoverflow.com/questions/8646517/see-the-size-of-a-github-repo-before-cloning-it) – azzamsa Mar 06 '18 at 21:48

8 Answers8

352

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.

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

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.)
Community
  • 1
  • 1
sehe
  • 374,641
  • 47
  • 450
  • 633
  • Thanks! The first behavior more accurately reflected the total clone size but the second was also pretty close. – mschallert Nov 18 '11 at 16:14
  • 9
    Note: this answer is out of date. See VonC's [answer](http://stackoverflow.com/a/16163608/241536) instead for git versions >= 1.8.3. – John Dibling Nov 14 '14 at 21:43
  • Note also my answer is a ways more complete, which could have it's own merit. – sehe May 17 '16 at 12:47
  • Can you please add what `git bundle` and `git gc` actually does? will it create another (unwanted) archive and then measure the size? – Ramesh Pareek May 25 '16 at 11:02
  • 1
    @RameshPareek yes. This is pretty clear because I'm using `du` to measure the size of that file. – sehe May 25 '16 at 11:48
  • @sehe 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? – CKM May 21 '20 at 13:51
  • @CKM 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. – sehe May 21 '20 at 17:14
  • 1
    This is the best answer because it shows the REAL size, even after 1.8.3 ver. – Felipe Jul 16 '23 at 05:40
138

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.

user1338062
  • 11,939
  • 3
  • 73
  • 67
Jack Morrison
  • 1,623
  • 1
  • 10
  • 13
  • 5
    In my experience, `git count-objects -v` works when `git-count-objects -v` does not (because it is not in my PATH). – mwolfetech Aug 07 '12 at 16:55
  • 6
    @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: http://stackoverflow.com/questions/3532740/do-i-ever-need-to-run-git-gc-on-a-bare-repo – Jack Morrison Mar 29 '13 at 20:20
  • 6
    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 @VonC said in his answer. – alko989 Jun 18 '14 at 11:44
  • 1
    `git count-objects --help`: size-pack: disk space consumed by the packs, in KiB (unless -H is specified) – auralbee Jan 04 '16 at 09:02
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.

serv-inc
  • 35,772
  • 9
  • 166
  • 188
  • 1
    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). – NH. Oct 25 '18 at 16:44
  • @IndrajeetGour: you need to install from https://github.com/github/git-sizer/#getting-started. Downloads are at https://github.com/github/git-sizer/releases. – serv-inc Jan 11 '19 at 13:06
  • 1
    Would the @downvoter care to explain his reasoning, or not? – serv-inc Feb 05 '19 at 03:37
  • If you are on macos, you can install it using homebrew. – James Selvakumar Mar 25 '22 at 07:34
  • 1
    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. – Adam E. Apr 13 '22 at 19:35
  • 2
    Adding to Jame's note, `brew install git-sizer` – Michael Roswell Apr 22 '22 at 14:17
9

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

Vivek Aggarwal
  • 109
  • 3
  • 3
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
elike
  • 61
  • 4
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.

user541686
  • 205,094
  • 128
  • 528
  • 886
  • Your commands gives me `29941282` but `du -sb .git/` says `19215458 .git/`, can you explain the difference ? – SebMa Nov 03 '20 at 15:15
  • @SebMa: Doesn't git compress things internally? (And encode identical files only once?) – user541686 Nov 03 '20 at 20:30
  • @SebMa 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. – mtutty Dec 10 '20 at 20:56
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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
RMPR
  • 3,368
  • 4
  • 19
  • 31
  • 1
    They are in different units (GB x GiB). By the way 1.71 GB = 1.84 GiB, just converting and not caring about rounds. – Luciano Feb 04 '20 at 16:57
  • Sorry, I mixed them up when typing, the correct relation: 1.71 GiB = 1.84 GB – Luciano Feb 06 '20 at 16:06
  • the repo filesize label relies on the github api response, that can be incomplete as of githubs statement. See updated comment at https://stackoverflow.com/a/8679592/7010943 concerning shared repository objects – wbob Jul 28 '22 at 10:29