Skip to content

Instantly share code, notes, and snippets.

@nickboldt
Last active January 24, 2024 03:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nickboldt/4a8426626e933ffb3d000717d04403f1 to your computer and use it in GitHub Desktop.
Save nickboldt/4a8426626e933ffb3d000717d04403f1 to your computer and use it in GitHub Desktop.
faster git checkout options
#!/bin/bash
# for large repos or repos with binary blobs in them, this is much faster
FORK=https://github.com/rhdh-bot/openshift-helm-charts.git
GIT_DIR=/tmp/catalog
BRANCH=rhdh-1-rhel-9
# under 2 seconds
# remote: Counting objects: 100% (4/4), done.
# remote: Compressing objects: 100% (4/4), done.
# remote: Total 4 (delta 0), reused 4 (delta 0), pack-reused 0
# Receiving objects: 100% (4/4), 1.97 KiB | 1.97 MiB/s, done.
function sparseclone {
pushd /tmp >/dev/null
rm -fr $GIT_DIR
git clone --filter=blob:none --no-checkout --depth=1 -q "${FORK}" "${GIT_DIR}" && cd "${GIT_DIR}"
git sparse-checkout init --cone
git read-tree -mu HEAD
git checkout -q -b "${BRANCH}" 1>/dev/null 2>&1 || true
git pull $QUIET origin "${BRANCH}" 1>/dev/null 2>&1 || true
popd >/dev/null
# note: must use `git add [files] --sparse` to add files into the index when committing changes
}
# >2m40s
# remote: Counting objects: 100% (2567/2567), done.
# remote: Compressing objects: 100% (1205/1205), done.
# remote: Total 2567 (delta 824), reused 2273 (delta 727), pack-reused 0
# Receiving objects: 100% (2567/2567), 46.58 MiB | 293.00 KiB/s, done.
# Resolving deltas: 100% (824/824), done.
function shallowclone {
pushd /tmp >/dev/null
rm -fr $GIT_DIR
git clone --depth=1 "${FORK}" "${GIT_DIR}" -b "${BRANCH}"
popd >/dev/null
}
# >2m40s
# remote: Counting objects: 100% (306/306), done.
# remote: Compressing objects: 100% (165/165), done.
# remote: Total 12587 (delta 152), reused 294 (delta 141), pack-reused 12281
# Receiving objects: 100% (12587/12587), 54.11 MiB | 342.00 KiB/s, done.
# Resolving deltas: 100% (5773/5773), done.
function normalclone {
pushd /tmp >/dev/null
rm -fr $GIT_DIR
git clone "${FORK}" "${GIT_DIR}" -b "${BRANCH}"
popd >/dev/null
}
time sparseclone
time shallowclone
time normalclone
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment