How to check the size of a git repository

How to check the size of a git repository

Table of Contents


Getting the tool and setting things up

First before we can start, we need to get the tool. The git-sizer tool can be found here and it is really easy to install.

NOTE:

  • Make sure you have the Git CLI installed (version >= 2.6)
  • Also makse sure that git command is available in your PATH

Install git-sizer on Windows

  1. Install a released version of git-sizer(recommended):
    • Go to the releases page and download the ZIP file corresponding to your platform.
    • Unzip the file.
    • Move the executable file (git-sizer or git-sizer.exe) into your PATH.

NOTE: The easiest is to copy the excutable to the same path were git is installed, as that is already part of your PATH

Pro Tip: If git-sizer is part of your PATH, you can run it by either typing git-sizer or git sizer. In latter case, it is found and run for you by Git, and you can add extra Git options between the two words

How to use git-sizer

To get detailed information about the size of a git repository, you can use the git-sizer --verbose command. By default using git-sizer it will only show problematic areas.

❯ git sizer --verbose
Processing blobs: 5051
Processing trees: 5112
Processing commits: 1054
Matching commits to trees: 1054
Processing annotated tags: 0
Processing references: 120
| Name                         | Value     | Level of concern               |
| ---------------------------- | --------- | ------------------------------ |
| Overall repository size      |           |                                |
| * Commits                    |           |                                |
|   * Count                    |  1.05 k   |                                |
|   * Total size               |   471 KiB |                                |
| * Trees                      |           |                                |
|   * Count                    |  5.11 k   |                                |
|   * Total size               |  2.13 MiB |                                |
|   * Total tree entries       |  54.3 k   |                                |
| * Blobs                      |           |                                |
|   * Count                    |  5.05 k   |                                |
|   * Total size               |  59.3 MiB |                                |
| * Annotated tags             |           |                                |
|   * Count                    |     0     |                                |
| * References                 |           |                                |
|   * Count                    |   120     |                                |
|     * Branches               |    27     |                                |
|     * Tags                   |     7     |                                |
|     * Remote-tracking refs   |    85     |                                |
|     * Git stash              |     1     |                                |
|                              |           |                                |
| Biggest objects              |           |                                |
| * Commits                    |           |                                |
|   * Maximum size         [1] |  1.20 KiB |                                |
|   * Maximum parents      [2] |     2     |                                |
| * Trees                      |           |                                |
|   * Maximum entries      [3] |   185     |                                |
| * Blobs                      |           |                                |
|   * Maximum size         [4] |  3.35 MiB |                                |
|                              |           |                                |
| History structure            |           |                                |
| * Maximum history depth      |   625     |                                |
| * Maximum tag depth          |     0     |                                |
|                              |           |                                |
| Biggest checkouts            |           |                                |
| * Number of directories  [5] |   561     |                                |
| * Maximum path depth     [5] |    10     | *                              |
| * Maximum path length    [6] |    96 B   |                                |
| * Number of files        [5] |  2.63 k   |                                |
| * Total size of files    [5] |  21.3 MiB |                                |
| * Number of symlinks         |     0     |                                |
| * Number of submodules       |     0     |                                |

[1]  48c5116db547c885966333231a3dd0998c01f748
[2]  df063044a2c4e4caf20085773e46bc848cd805cd (refs/tags/v1.0.6)
[3]  fcb2391a4f394e51b9ef22ef193a76bd653b06fe (refs/remotes/origin/feature/update-npm:node_modules/npm/node_modules)
[4]  a8cf3760f503fa07db8803f242c7f4a3878e1564 (refs/heads/feature/upgrade-dotnet6:src/Web/src/assets/logo.png)
[5]  803ca70b7a8c19cb71b53c59513642232c7e1c13 (refs/remotes/origin/feature/update-npm^{tree})
[6]  75b4a8b14d79d628770d0ff953f9f893f8420885 (refs/heads/feature/upgrade-dotnet6^{tree})

The output is a table showing what was measureed and a rough indiction of which values might be problematic. Note: Only objects that are reachable from references are included.

The “Overall repository size” section includes repository-wide statistics about distinct objects, not including repetition. “Total size” is the sum of the sizes of the corresponding objects in their uncompressed form, measured in bytes. The overall uncompressed size of all objects is a good indication of how expensive commands like git gc --aggressive (and git repack [-f|-F] and git pack-objects --no-reuse-delta), git fsck, and git log [-G -S] will be. The uncompressed size of trees and commits is a good indication of how expensive reachability traversals will be, including clones and fetches and git gc.

This is the default output using one of the famouse “git bomb” repositoriy repositories:

$ git-sizer
[...]
| Name                         | Value     | Level of concern               |
| ---------------------------- | --------- | ------------------------------ |
| Biggest checkouts            |           |                                |
| * Number of directories  [1] |  1.11 G   | !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| * Maximum path depth     [1] |    11     | *                              |
| * Number of files        [1] |     ∞     | !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| * Total size of files    [2] |  83.8 GiB | !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |

[1]  c1971b07ce6888558e2178a121804774c4201b17 (refs/heads/master^{tree})
[2]  d9513477b01825130c48c4bebed114c4b2d50401 (18ed56cbc5012117e24a603e7c072cf65d36d469^{tree})