Skip to content

Instantly share code, notes, and snippets.

Embed
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 hello.md -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 https://gist.github.com/drio/75b711b43af ./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:

#!/bin/bash
# vim: ft=sh:
set -e

GIST_DIR="$HOME/dev/gist.github.com"

mkdir -p $GIST_DIR
cd $GIST_DIR

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

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 https://gist.github.com/drio/$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