]> git.phdru.name Git - git-scripts.git/blobdiff - sparse-clone
Add `sparse-clone`
[git-scripts.git] / sparse-clone
diff --git a/sparse-clone b/sparse-clone
new file mode 100755 (executable)
index 0000000..5bbaa6b
--- /dev/null
@@ -0,0 +1,22 @@
+#! /bin/sh
+# Adapted from https://stackoverflow.com/a/13738951/7976758
+set -e
+
+rurl="$1"
+localdir="$2"
+shift 2
+
+mkdir -p "$localdir"
+cd "$localdir"
+
+git init
+git remote add origin "$rurl"
+
+git config core.sparseCheckout true
+
+# Loops over remaining args
+for arg; do
+  echo "$arg" >> .git/info/sparse-checkout
+done
+
+exec git pull origin master