Skip to content

count-objects Git Command Guide

The git count-objects command counts the number of unpacked objects in a Git repository and displays their disk consumption. This helps monitor repository size and decide when to run git gc or git repack.

Terminal window
git count-objects [-v|--verbose] [-H|--human-readable]
OptionDescription
-v, —verboseShow detailed information including size in different units
-H, —human-readablePrint sizes in human-readable format (e.g. 5.0M, 2.0G)
-h, —helpDisplay help information
ParameterDescription
None supported - operates on current repositoryN/A
Terminal window
git count-objects

Shows count of loose objects and disk size (counts only).

Terminal window
git count-objects -v

Displays detailed statistics including pack counts and sizes.

Terminal window
git count-objects -H

Shows sizes in human-readable format like 1.2M, 500K.

Terminal window
git count-objects -v -H

Provides complete information in readable format.

How do I count the objects in a Git repository?

Section titled “How do I count the objects in a Git repository?”

To count the objects in a Git repository, use:

Terminal window
git count-objects

To see detailed object statistics, run:

Terminal window
git count-objects -v

How do I see sizes in human-readable format?

Section titled “How do I see sizes in human-readable format?”

To see sizes in human-readable format, execute:

Terminal window
git count-objects -H

Run git count-objects when you want to monitor repository size growth or decide if it’s time to run garbage collection.

git count-objects measures the number of loose objects and their disk consumption in the .git/objects directory.

Applications of the git count-objects command

Section titled “Applications of the git count-objects command”
  1. Monitoring repository growth and determining when to run garbage collection
  2. Analyzing repository structure and object distribution
  3. Diagnosing repository bloat and identifying cleanup opportunities
  4. Tracking the effectiveness of git gc and git repack operations
  5. Providing metrics for repository health monitoring
  6. Debugging issues with repository size after large operations