Skip to content

Instantly share code, notes, and snippets.

@afriza
Last active January 1, 2023 03:25
Show Gist options
  • Save afriza/6c13369d060c3361a06892e039ab9cf0 to your computer and use it in GitHub Desktop.
Save afriza/6c13369d060c3361a06892e039ab9cf0 to your computer and use it in GitHub Desktop.
Convert git repository into shallow clone to save storage space when there is no need for git histories
#! /bin/sh
# Ref: https://stackoverflow.com/a/62650346/109747
# macOS/BSD find requires root path
root=${1:-.}
# TODO: handle if git-shallow.sh exits with non-zero code
find $root -type d -name '.git' -exec sh -c 'pushd "${0%/*}" && ( git-shallow.sh ) && popd' {} \;
#! /bin/sh
# Convert current git repository into shallow clone.
# Useful to save storage/space when there is no need for git histories.
# Ref: https://stackoverflow.com/a/62650346/109747
# pull latest code from current remote-tracking branch
git pull --depth 1
# WARNING: remove all tags
git tag -d $(git tag -l)
# WARNING: remove all backup references of local historical operations
git reflog expire --expire=all --all
# WARNING: remove unreachable objects
# NOTE: objects reachable from local/remote branches are probably not removed
git gc --prune=all
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment