Skip to content

Instantly share code, notes, and snippets.

@miku
Forked from chenchun/clone-all-gists.sh
Last active March 3, 2026 14:07
Show Gist options
  • Select an option

  • Save miku/4502324062dc5437f98f965046920c04 to your computer and use it in GitHub Desktop.

Select an option

Save miku/4502324062dc5437f98f965046920c04 to your computer and use it in GitHub Desktop.
clone all gists and better search them with your own tools #github #gists
#!/bin/bash
set -eu -o pipefail
token="${GITHUB_TOKEN:?Set GITHUB_TOKEN before running this script}"
clone_or_pull() {
local page="$1"
local tmpfile
tmpfile=$(mktemp)
trap "rm -f '$tmpfile'" RETURN
curl -sfL \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $token" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"https://api.github.com/gists?per_page=100&page=$page" >"$tmpfile"
local id url
while IFS=$'\t' read -r id url; do
if [ -d "$id" ]; then
git -C "$id" pull --quiet
else
git clone --quiet "$url"
fi
done < <(jq -r '.[] | [.id, .git_pull_url] | @tsv' "$tmpfile")
jq length "$tmpfile"
}
page=1
count=0
while true; do
length=$(clone_or_pull "$page")
count=$((count + length))
if [ "$length" -lt 100 ]; then
break
fi
page=$((page + 1))
done
echo "total $count gists"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment