Last active
February 5, 2024 13:15
-
-
Save bombsimon/b7272abaaf002ae53dd74381cc390c8d to your computer and use it in GitHub Desktop.
✏️ Easily clone a gist to a regular git repository
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
#!/bin/sh | |
set -eu | |
gi() { | |
name="${1:-}" | |
gist="${2:-}" | |
if [ "$name" = "" ]; then | |
echo "Missing gist name" | |
exit 1 | |
fi | |
if [ "$gist" = "" ]; then | |
echo "Missing gist URL" | |
exit 1 | |
fi | |
mkdir "$name" && cd "$name" | |
hash=$(basename "$gist") | |
git init | |
git remote add origin "git@gist.github.com:${hash}.git" | |
git fetch | |
remote_branch="$(basename "$(git branch --remotes)")" | |
git checkout "$remote_branch" | |
} | |
gi "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment