Git/Shallow
< Git
Shallow Clone
git clone --filter=blob:none <url> creates a blobless clone. ... git clone --filter=tree:0 <url> creates a treeless clone. ... git clone --depth=1 <url> creates a shallow clone.
Convert Cloned Repo to Shallow
git clone --depth-1 <repo> -b <branch> git clone --depth 1 org-1234@github.com:MYORG/MYREPO.git -b MYREPO/MYBRANCH MYBRANCH git clean -x -f -d . git pull --depth 1 git fetch --depth 1 git reflog expire --expire=0 git reflog expire --expire=now --all git show-ref -s HEAD git show-ref -s HEAD > .git/shallow git prune git prune-packed git repack git pull --shallow-since=1999-01-01 git pull --shallow-since=2026-03-19 git gc git gc --prune=all git gc --prune=now git gc --aggressive git tag -d $(git tag -l) git fsck --full --no-reflogs # fix: # $ git gc # warning: reflog of 'HEAD' references pruned commits git reflog expire --all --stale-fix git gc du --si --max-depth=1
UPDATED BRUTE FORCE CONVERSION METHOD
git config remote.origin.fetch "+refs/heads/MYREPO/MYBRANCH:refs/remotes/origin/MYREPO/MYBRANCH"
rm -rf .git/objects/*
## optional cleanup: rm -f .git/info/refs
## optional cleanup: rm -f .git/{COMMIT_EDITMSG,}
# optional: rm .git/hooks/*
# optional: rm -rf .git/lfs
# optional: rm -rf .git/refs/*
# optional: rm -rf .git/logs/*
rm .git/packed-refs
git reflog expire --all --stale-fix
git fetch
git checkout MYREPO/MYBRANCH
git pull
git gc
du --si --max-depth=1
BRUTE FORCE CONVERSION METHOD
cd .git # delete top level files --- # dir: branches/ hooks/ info/ lfs/ logs/ objects/ refs/ # files: COMMIT_EDITMSG config description FETCH_HEAD HEAD index ORIG_HEAD packed-refs shallow # removes extras: COMMIT_EDITMSG, FETCH_HEAD # ignore unused: description rm -f * # remove lfs/ rm -rf lfs/ # clear logs/ and sub-dirs rm -rf logs/* # clear hooks/ rm hooks/* # clear write-projected objects/pack #rm -f objects/pack/* #rm objects/info/packs rm -rf objects/* # remove refs rm -rf refs/* rm info/refs rm COMMIT_EDITMSG rm packed-refs # will be recreated: rm FETCH_HEAD # make origin head shallow cat ORIG_HEAD > shallow # fix config: # [origin] # replace: fetch = +refs/heads/*:refs/remotes/origin/* # with: fetch = +refs/heads/MYREPO/MYBRANCH:refs/remotes/origin/MYREPO/MYBRANCH git config --get remote.origin.fetch +refs/heads/*:refs/remotes/origin/* # git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*" ## Limit fetch to just the one branch: git config remote.origin.fetch "+refs/heads/MYREPO/MYBRANCH:refs/remotes/origin/MYREPO/MYBRANCH" git config --get remote.origin.fetch +refs/heads/MYREPO/MYBRANCH:refs/remotes/origin/MYREPO/MYBRANCH # copy shallow copies .git/* -- config, description, FETCH_HEAD, HEAD, ORIG_HEAD, packed-refs, shallow # extras: cp ../../shallow/.git/* ./ cd .. # Fetch - should only fetch the current branch only git fetch