Skip to content

Instantly share code, notes, and snippets.

@sahal
Last active January 30, 2026 20:03
Show Gist options
  • Select an option

  • Save sahal/0472f2e7e97cf0ce065035e64191348c to your computer and use it in GitHub Desktop.

Select an option

Save sahal/0472f2e7e97cf0ce065035e64191348c to your computer and use it in GitHub Desktop.
Backup your Public and Private Gists

Backup your Public and Private Gists

Use bash+curl+github api to download your gists. Gists are not exported when you Download your account data via export, unfortunately.

For more details check out the documentation on REST API endpoints for gists and gist comments

Token

Get your fine-grained personal access token. Make sure you have access to gists.

List of public and private gists

Note: If you don't care about getting your private gists, you can just skip the Authorization header below.

curl -L \
  -H "Accept: application/vnd.github+json" \
  -H "Authorization: Bearer <YOUR-TOKEN>" \
  -H "X-GitHub-Api-Version: 2022-11-28" \
  https://api.github.com/gists > list-of-gists.json

Start cloning your gists

mkdir -p {public,private}
jq '.[]| select(.public == false)' ./list-of-gists.json > ./private/private-gists.json
jq '.[]| select(.public == true)' ./list-of-gists.json > ./public/public-gists.json

pushd public
for url in $(jq -r '.git_pull_url' public-gists.json); do git clone "${url}" || true ; done
popd
pushd private
for url in $(jq -r '.git_pull_url' private-gists.json); do git clone "${url}" || true ; done
popd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment