Skip to content

Instantly share code, notes, and snippets.

@cppio
Created April 25, 2020 17:43
Show Gist options
  • Select an option

  • Save cppio/1fb6c9785a1e6c08395432205ce1bce5 to your computer and use it in GitHub Desktop.

Select an option

Save cppio/1fb6c9785a1e6c08395432205ce1bce5 to your computer and use it in GitHub Desktop.
A simple script to get specific files from a git repo without cloning the whole thing.
#!/bin/bash
shopt -s dotglob nullglob
dest="$(pwd)"
tempdir="$(mktemp -d)"
git clone --depth 1 --no-checkout --filter=blob:none "${1%%@*}" "$tempdir"
tag="$(tag=${1#*@}; repo="${1##*@*}"; repo="${repo:+HEAD}"; echo "${repo:-$tag}")"
shift
cd "$tempdir"
git checkout "$tag" -- "$@"
rm -rf .git
mv * "$dest" 2>&-
rm -rf "$tempdir"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment