Over a million developers have joined DZone.

Introducing 'Git Size' (Command and Visualization)

Paul Hammant shares two commands for Git to help manage space on your hard drive.

· DevOps Zone

The DevOps zone is brought to you in partnership with Sonatype Nexus. The Nexus suite helps scale your DevOps delivery with continuous component intelligence integrated into development tools, including Eclipse, IntelliJ, Jenkins, Bamboo, SonarQube and more. Schedule a demo today

I’m trying to slim things down — it’s easy to fill a 256GB hard drive on a Mac when you like poking around other people’s source code on GitHub. And, perhaps, 100 of your own repos.

I wrote two commands for Git in bash to supplement Git.

Git Size

As run on my Mac (after I zapped 50GB of git repos):

The ‘git size’ sub-command: https://github.com/paul-hammant/git-size (~patches~ PRs welome).

Running It 

$ git size jbehave/jbehave-core/
jbehave/jbehave-core: git size:
  .git folder:  31M
  checkout: 11.6M
  ignored: 8.1M
  total:  50M 

Or, recursive and CSV:

$ git size --csv --csv-headers --recursive .


How to install that on a Mac with Homebrew (so you can just do ‘git size’ like other git commands): github.com/paul-hammant/homebrew-tap#git-size


The site for visualizations: https://paul-hammant.github.io/git-size/. It is the gh-pages branch of the git-size repo, of course.

That pic is the example linked to from the homepage, above. The link itself (so you can see):

https://paul-hammant.github.io/git-size/total.html#ImpiZWhhdmUvamJlaGF2ZS1jb3JlIiwzMTMyMCwx MTkyNCw4MzQ0LDUxNTg4CiJqYmVoYXZlL2piZWhhdmUtdHV0b3JpYWwiLDcyOCwyMjAsMCw5NDgKImpiZWhhdmUvamJl aGF2ZS13ZWIiLDE3NzIsMTM5Niw5MjAsNDA4OAoibWF2ZW4taHBpLXBsdWdpbiIsMTc4NCw2MjAsMTMyOCwzNzMyCiJ4 dW5pdC1wbHVnaW4iLDE0MTYsMzU4OCwxNDkyOCwxOTkzMgo=

Yes, that’s a long URL. It’s OK the browser can handle it. Note that the stuff to the right of the # will not be sent to the Github web-server hosting the files. The stuff to the right of the # is a base64 encoded form of the CSV above, or course.

Git Slim

This might be buggy, but it works for me - a way to reduce the depth of a clone in-situ.

The ‘git slim’ sub-command: https://github.com/paul-hammant/git-slim

$ cd jbehave/jbehave-core
$ git slim
Size of .git folder before:  31M, best case size after: 3.4M (approx).


How to install that on a Mac (so you can just do ‘git slim’ as any git command): github.com/paul-hammant/homebrew-tap#git-slim

Thoughts After Making These

Bash is quite picky generally, but there’s a particular snafu that bogged me down quite a bit:

Unix command xargscan blow up when using it to calculate the size of a list of files. I had to drop it, and iterate over files adding up KB sizes. There’s a -a option but it’s not available installed on base OS X.

I could have installed GNU’s xargs like so brew install findutils, but it would be gxargs instead of xargs and though still possible, it would be harder to keep git-size Linux compatible.

The D3-using sunburst chart really has to stay online - it is too much for a simple bash-script to handle. It is also a fork of something pre-existing, and I had trouble making it into a single page that could switch between the four size types passed in via CSV (the four radio buttons at the top).

Lastly, I really wanted to do a treemap, but nothing in JavaScript/SVG was quite as pretty as the treemap of the fabled Disk Inventory X. So sunburst it was.

The DevOps zone is brought to you in partnership with Sonatype Nexus. Use the Nexus Suite to automate your software supply chain and ensure you're using the highest quality open source components at every step of the development lifecycle. Get Nexus today

git ,bash

Published at DZone with permission of Paul Hammant, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}