Skip to content

Instantly share code, notes, and snippets.

@bombsimon
Last active February 5, 2024 13:15
Show Gist options
  • Save bombsimon/b7272abaaf002ae53dd74381cc390c8d to your computer and use it in GitHub Desktop.
Save bombsimon/b7272abaaf002ae53dd74381cc390c8d to your computer and use it in GitHub Desktop.
✏️ Easily clone a gist to a regular git repository
#!/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