Git: Finding Repo Size

git-smGit is a tool I use daily. I am not a master of Git by any means, but I’m always looking to enhance my knowledge in tools I use regularly. I wanted to find a way to be able to see how many megabytes a given Git repository is. Thankfully git is very flexible and has tools for this.After some Google searching I found that git has the command count-objects:

git-count-objects – Count unpacked number of objects and their disk

git count-objects [-v] [-H | –human-readable]

This counts the number of unpacked object files and disk space consumed by
them, to help you decide when it is a good time to repack.

Being aware of this I tried using this command on a local git repository and it gave me the information I wanted. Its output has the same structure always — so I then wanted to create 2 bash functions which:

  • examine if we are in a Git repository folder, and if so then
  • use git count-objects to output the size of the repository on-disk.

The simple bash functions I wrote are as follows. I typically place such functions into my .bash_aliases file and source it on system startup.

function is-cwd-git-repo() {
  local answer=''
  if [ -d .git ]; then
    answer=$(echo .git)
    answer=$(git rev-parse --git-dir 2> /dev/null)
  return [[ "$answer" ]] && 0 || 1

function git-repo-size() {
  local size=''
  if [ is-cwd-git-repo ]; then
      size=$(git count-objects -vH | grep "size-pack" | sed 's/size-pack: //')
      echo "git repo is ${size}."
    echo "not in git repo."
    return 1;

An example run from a git repository of mine is:

✔ aw-dgurba /var/www/2014/my-app esci-20141-shortfixes > git-repo-size 
git repo is 3.85 MiB.

So I can examine the filesizes of any git repository I am working on if I’m curious of the repo size. Git provides other useful tools to manage and archive repositories, such as git-repack and git-archive.

Looking for quality web hosting? Look no further than Arvixe Web Hosting!

Tags: , , , , , , , , , | Posted under 3rd Party Software | RSS 2.0

Author Spotlight

David Gurba

I am a web programmer currently employed at UCSB. I have been developing web applications professionally for 8+ years now. For the last 5 years I’ve been actively developing websites primarily in PHP using Drupal. I have experience using LAMP and developing data driven websites for clients in aviation, higher education and e-commerce. If you’d like to contact me I can be reached at

Leave a Reply

Your email address will not be published. Required fields are marked *