Yes this is possible, the following git-commands are shell-script functions, but really they could be bat files or similar.
# clone
function git_shallow_clone() {
git clone --depth 1 --single-branch $@
}
# pull
function git_shallow_pull() {
git pull --no-tags $@
# clean-up, if a new revision is found
git show-ref -s HEAD > .git/shallow
git reflog expire --expire=0
git prune
git prune-packed
}
# make an existing clone shallow (handy in some cases)
function git_shallow_make() {
# delete all branches except for the current branch
git branch -D `git branch | grep -v $(git rev-parse --abbrev-ref HEAD)`
# delete all tags
git tag -d `git tag | grep -E '.'`
# delete all stash
git stash clear
# clean-up, if a new revision is found (same as above)
git show-ref -s HEAD > .git/shallow
git reflog expire --expire=0
git prune
git prune-packed
}
# load history into a shallow clone.
function git_shallow_unmake() {
git fetch --no-tags --unshallow
}
Notes
--no-tags
is important to use, otherwise you may clone tags which have sha1
s pointing to blob's outside of the branch master
- restricting to a single branch is also useful, assuming you're only interested in
master
, or a single branch at least
- re-enforcing shallow after every pull seems quite a heavy operation, but I didn't find a better way
Thanks to: https://stackoverflow.com/a/7937916/432509 (for the important part of this answer)