Last active
January 1, 2023 03:25
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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' {} \; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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