Skip to content

Instantly share code, notes, and snippets.

@drio
Last active July 20, 2022 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drio/9acbdd4b1960c926cfcb592807319f2c to your computer and use it in GitHub Desktop.
Save drio/9acbdd4b1960c926cfcb592807319f2c to your computer and use it in GitHub Desktop.
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