-
-
Save jeremyBanks/8d1837445cb1375d9b1c to your computer and use it in GitHub Desktop.
0x10-line bash script to mirror current repo to private gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
if ! git remote 2>/dev/null | grep -qE '^gist$' # if not previously gisted, create new gist and mirror | |
then if [ -z "$(git config github.token)" ] # we warn but procede if no api token is set | |
then echo "warning: no api token found, to add follow instructions on github account page."; fi | |
echo "creating a new gist using your github authentication..." | |
SHA=$(curl https://gist.github.com/gists --include -sS \ | |
--data login=$(git config github.user) \ | |
--data token=$(git config github.token) \ | |
--data action_button=private \ | |
--data 'file_ext[gistfile1]=txt&file_contents[gistfile1]=..?' \ | |
| perl -e 'for(<>){if(/^Location: *https?:\/\/gist.github.com\/([0-9a-f]+)/){print $1}}') | |
if [ "$SHA" ]; then if ! git branch &>/dev/null; then git init; fi # if not in repo, init | |
git remote add gist git@gist.github.com:$SHA.git | |
echo "mirroring to new remote \"gist\" at git@gist.github.com:$SHA.git..." | |
git push --mirror gist # --mirror to force out initial gist contents | |
else echo "error: failed to create new gist"; false; fi | |
else git push --all gist; fi # if already gisted, push commited changes |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment