unixorn/git-extra-commands

View on GitHub
bin/git-shrink-repo

Summary

Maintainability
Test Coverage
#!/usr/bin/env bash
#
# Shrink your git repo
#
# MIT License
#
# Based on @gimbo's https://github.com/gimbo/gimbo-git.zsh/blob/master/gimbo-git.zsh

set -o pipefail

if [[ "$(git stash list | wc -l)" -eq 0 ]]; then
  du -hs "$(git rev-parse --show-toplevel)/.git"
  git reflog expire --expire=now --all
  git gc --prune=now
  du -hs "$(git rev-parse --show-toplevel)/.git"
else
  echo 'Refusing to shrink because your stash is not empty.'
  exit 1
fi