Skip to content

Instantly share code, notes, and snippets.

@craig-m
Last active December 29, 2022 13:53
Show Gist options
  • Save craig-m/ce50322b67ad700856fe22d3e63f98c5 to your computer and use it in GitHub Desktop.
Save craig-m/ce50322b67ad700856fe22d3e63f98c5 to your computer and use it in GitHub Desktop.
backup all gists with gh command

gist backup with gh

Install the offical Github cli tool from here, login, and then dump all gists:

gh auth login
mkdir ~/gists
cd ~/gists
gh gist list | awk '{print $1}' | xargs -I{} gh gist clone {}

to update them:

cd ~/gists
find . -not -path "./gisthub-bu" -mindepth 1 -maxdepth 1 -type d -print -exec git -C {} pull --ff-only \;
#!/usr/bin/env bash
IFS=$'\n'
set -f
set -e
printf "start git BU\n"
gh gist list | awk '{print $1}' > gists.txt
for i in $(cat < "gists.txt"); do
printf "Gist: $i\n";
[ -d "$i" ] && echo 'updating' && git -C $i pull --ff-only;
[ ! -d "$i" ] && echo 'new gist' && gh gist clone $i;
sleep 1;
printf '\n';
done
printf "git BU finished\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment