How to create a gist on command line

I've just tried

curl -X POST -d '{"public":true,"files":{"test.txt":{"content":"String file contents"}}}' -u mgarciaisaia:mypassword https://api.github.com/gists

and it worked: https://gist.github.com/mgarciaisaia/fa51238073eb2cf508aa

I don't see any problem in your command.


This question is old, so I am not sure it is still relevant.

On Ubuntu (at least on 18.04), you can try the gist package, which will install the gist-paste command that you can use (given you have a git account already) as below:

1) Get a gist OAuth2 token (it will create a ~/.gist file with the token). You have to do it once only:

$ gist-paste --login

Then, you can send your files, for instance:

$ gist-paste your-file.txt
$ cat .emacs.d/init.el | gist-paste -t el

There are many options: You can send file type/description (as above second example), delete gists, open gist in browser, etc... See gist-paste(1) or try gist-paste --help.

If you already have a gist token, you don't need to run gist-paste --login, just copy your ~/.gitconfig's oauth-token to ~/.gist. For example, if you have in ~/.gitconfig:

[github]
    oauth-token = foobar123

Just create a ~/.gist file with one line containing "foobar123".

[Edit] If your distribution does not provide the package, the project page is: https://github.com/defunkt/gist


Recently GitHub CLI released. So you can now use it instead.

Just install it to your system (https://github.com/cli/cli#installation)

The authenticate (it's pretty simple)

gh auth login

After you logged in you can simply create a new gist by:

gh gist create -d "my test gist" -f some_local_file.txt  test_gist

For more details you can use help:

gh <command> <subcommand> --help