Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
how to gist from cli

How to gist from the cli

To create a new gist from cli:

$ gh gist create -d "hello world" -p -w

Then you can list your gist:

$ gh gist list

And clone it as if it was a git repo:

$ gh gist clone ./repo_name

At this point you can interact with it as a regular git repo. So we can make changes and push upstream:

$ date > date.txt
$ git commit -a -m 'add date'
$ git push -u origin main

I was getting auth issues when pushing changes to the gist repos. I think I solved it by doing gh auth setup-git.

Starting a new gist repo

With something like this you can start a gist repo locally:

# vim: ft=sh:
set -e


mkdir -p $GIST_DIR

if [ ".$1" == "." ];then
  echo "Need a repo name as first argument"
  exit 0

echo "Gist away!" | gh gist create -d "$repo_name" -f "index.txt" -p -w
sha=$(gh gist list | head -1 | awk '{print $1}')
gh gist clone$sha ./$repo_name
echo "New gist repo at: $GIST_DIR/$repo_name"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment