Check-out our new look and give us some feedback!
Reading Time: 7 minutes

What is Gist?

Gist is an easy method to share snippets or excerpts of data with others. A gist can be a string of code, a bash script or some other small piece of data. These bits of information are hosted by GitHub as a repository. Using gist has all the benefits of utilizing a GitHub repository, and also provides a more lightweight way of utilizing GitHub’s versioning features. 

A gist can be either public or secret. If you are logged in to GitHub when you create a gist, it will show up in your dashboard. You can also drag and drop a file onto your gist editor and it will be added 

Not only are gists free to create and store on GitHub, but they are also easy to create. You can add a new gist, modify, and delete files and code entirely from within your browser. Lastly, there is no need to download or install a program to use gist.

How Do I Create a Gist?

Creating a gist is simple. Here are the steps to add a gist to your GitHub account.

1, Sign in to GitHub

2. Browse to your gist homepage.

3. Type in a name and description for our gist. 

create.gist

4. Type in the text you want to save into the text field. In this instance, we are adding a 'du -sk' command.

du.sort.gist

5. Select if the gist will be public or private. Click on your selection and your gist will be created.

gist.secret.public
Bonus:
If you are logged in to GitHub and on the main page, you also have the option of clicking on the plus sign “+” next to your profile icon as seen below. This will open a dropdown menu where you can select the “New gist” option.
github.menu.2

How Do I Edit or Delete a Gist?

In the top right corner of your gist page, there will be a menu that allows for multiple functions to be performed on your gist.

gist.actions

We can edit, delete, unsubscribe, star, embed, copy, share, and download a raw copy or zipped copy of a gist.

We also can share a gist in multiple ways. You can opt to embed the gist into a website, copy a shareable link to send, clone (or copy) the gist via the git command to a local repository or via SSH. 

embed.options

Review Your Gists

Once you have logged into your GitHub account, click on your username in the top right corner. This will open a menu where you can see an option called ‘Your gists’. 

github.menu

Once you clicked that option, you will see your gist page.

Create A Gist From the Command Line

We also can create a gist via the command line without having to actually log in to GitHub. This does require you to create a personal access token from the settings' menu.

github.access.token

Simply click on the “Generate new token” button on the top right-hand side. This will open a new window where you can create a new access token. Simply add a name for the token in the note field.

new.personal.access.token

Next, select a scope from the available options.

token.select.scope

We will choose the gist option.

create.gist.token

Then, we can click on the green “Generate token” button at the bottom of the available scopes page. This will open a new page that contains your new secret token.

personal.access.token

As the note states, Make sure you copy your new personal access token to a safe place as it will not be shown again.

We can now use that token as our password to access the GitHub API functions.

To add a gist via the command line, we can use the following command.

curl -X POST -d '{"public":true,"files":{"addgist.txt":{"content":"This is a cool way to add a gist!"}}}' -u MyUser:194be7ef18ae5c539cc75bd830f03d3487b118fc https://api.github.com/gists
  • This is all one command you will copy into your command line. 
  • You can modify the “public”:true, to false if you wish to add a secret gist.
  • You can modify the “Addgist.txt” to whatever you would like to name your gist. 
  • We can also add specific content to your gist by modifying the “This is a cool way to add a gist!" section.
  • Lastly, change the ‘MyUser’ option to your GitHub username, and then enter the personal access token we copied in the last step as your password.

When we run the above command, we will get output on the command line which looks like this.

root@host [~]# curl -X POST -d '{"public":true,"files":{"addgist.txt":{"content":"This is a cool way to add a gist!"}}}' -u MyUser:194be7ef18ae5c539cc75bd830f03d3487b118fc https://api.github.com/gists
{
  "url": "https://api.github.com/gists/8c1d63fa3400f1f00f3d63bf50670794",
  "forks_url": "https://api.github.com/gists/8c1d63fa3400f1f00f3d63bf50670794/forks",
  "commits_url": "https://api.github.com/gists/8c1d63fa3400f1f00f3d63bf50670794/commits",
  "id": "8c1d63fa3400f1f00f3d63bf50670794",
  "node_id": "MDQ6R2lzdDhjMWQ2M2ZhMzQwMGYxZjAwZjNkNjNiZjUwNjcwNzk0",
  "git_pull_url": "https://gist.github.com/8c1d63fa3400f1f00f3d63bf50670794.git",
  "git_push_url": "https://gist.github.com/8c1d63fa3400f1f00f3d63bf50670794.git",
  "html_url": "https://gist.github.com/8c1d63fa3400f1f00f3d63bf50670794",
  "files": {
    "addgist.txt": {
      "filename": "addgist.txt",
      "type": "text/plain",
      "language": "Text",
      "raw_url": "https://gist.githubusercontent.com/MyUser/8c1d63fa3400f1f00f3d63bf50670794/raw/8accd7ed7fc922e2f41ca8a0688756ac06d93105/addgist.txt",
      "size": 33,
      "truncated": false,
      "content": "This is a cool way to add a gist!"
    }
  },
  "public": true,
  "created_at": "2020-02-26T22:35:32Z",
  "updated_at": "2020-02-26T22:35:32Z",
  "description": null,
  "comments": 0,
  "user": null,
  "comments_url": "https://api.github.com/gists/8c1d63fa3400f1f00f3d63bf50670794/comments",
  "owner": {
    "login": "MyUser",
    "id": 5208558,
    "node_id": "MDQ6VXNlcjUyMDg1NTg=",
    "avatar_url": "https://avatars0.githubusercontent.com/u/5208558?v=4",
    "gravatar_id": "",
    "url": "https://api.github.com/users/MyUser",
    "html_url": "https://github.com/MyUser",
    "followers_url": "https://api.github.com/users/MyUser/followers",
    "following_url": "https://api.github.com/users/MyUser/following{/other_user}",
    "gists_url": "https://api.github.com/users/MyUser/gists{/gist_id}",
    "starred_url": "https://api.github.com/users/MyUser/starred{/owner}{/repo}",
    "subscriptions_url": "https://api.github.com/users/MyUser/subscriptions",
    "organizations_url": "https://api.github.com/users/MyUser/orgs",
    "repos_url": "https://api.github.com/users/MyUser/repos",
    "events_url": "https://api.github.com/users/MyUser/events{/privacy}",
    "received_events_url": "https://api.github.com/users/MyUser/received_events",
    "type": "User",
    "site_admin": false
  },
  "forks": [

  ],
  "history": [
    {
      "user": {
        "login": "MyUser",
        "id": 5208558,
        "node_id": "MDQ6VXNlcjUyMDg1NTg=",
        "avatar_url": "https://avatars0.githubusercontent.com/u/5208558?v=4",
        "gravatar_id": "",
        "url": "https://api.github.com/users/MyUser",
        "html_url": "https://github.com/MyUser",
        "followers_url": "https://api.github.com/users/MyUser/followers",
        "following_url": "https://api.github.com/users/MyUser/following{/other_user}",
        "gists_url": "https://api.github.com/users/MyUser/gists{/gist_id}",
        "starred_url": "https://api.github.com/users/MyUser/starred{/owner}{/repo}",
        "subscriptions_url": "https://api.github.com/users/MyUser/subscriptions",
        "organizations_url": "https://api.github.com/users/MyUser/orgs",
        "repos_url": "https://api.github.com/users/MyUser/repos",
        "events_url": "https://api.github.com/users/MyUser/events{/privacy}",
        "received_events_url": "https://api.github.com/users/MyUser/received_events",
        "type": "User",
        "site_admin": false
      },
      "version": "c42194dfef53dfb3d6fea5f057c29959af53e635",
      "committed_at": "2020-02-26T22:35:32Z",
      "change_status": {
        "total": 1,
        "additions": 1,
        "deletions": 0
      },
      "url": "https://api.github.com/gists/8c1d63fa3400f1f00f3d63bf50670794/c42194dfef53dfb3d6fea5f057c29959af53e635"
    }
  ],
  "truncated": false
}
root@host [~]# 

Now, if we go back to our gist list, we can see the new gist has been added!

new.command.line.gist2

How Can Gists Be Used?

There are multiple ways to utilize gists. Here are a few examples we have found that are very useful in our daily activities.

  • As a task lists.
  • Organize notes.
  • As a writing platform.
  • To Save links.
  • To Write anonymous text.
  • Track text changes.
  • Publish rich text gists (using markdown and saving as an .md file).
  • To host a simple website.
  • Code can be embedded within a web page or WordPress post.
  • Can be used to bookmark websites. 
  • Store configuration or other .dotfiles.
  • Share gists on social media.
  • Associate multiple files to a single Gist.
  • Miniblog.
  • 'Secret' Text gist.
  • Sync VS Code as a gist.
  • Use a Python gist as a command line client.
  • The API is straightforward to integrate with your project or software. When creating a gist, you can easily send a POST request to add a gist.
  • Reviewing tool to exchange/review info with others.
  • Upload images to a gist — clone your gist as a git repository and add your picture, then push to origin. 
  • Backup with versioning.

Other Uses For Gists

In addition to the above uses, this post outlines how gist can be uses as a syntax highlighter. There are also several third-party services that have been created specifically around the use of gists.

Conclusion

As you can see, gist are a handy way to store random data you create. Gists have a multitude of uses that is only limited by your imagination!

Have questions about how gists can be more useful? Give us a call at 800.580.4985, or open a chat or ticket with us to speak with one of our knowledgeable Solutions Team or an experienced Hosting Advisor today!

About the Author: David Singer

I am a g33k, Linux blogger, developer, student, and former Tech Writer for Liquidweb.com. My passion for all things tech drives my hunt for all the coolz. I often need a vacation after I get back from vacation....

Latest Articles

How to Edit Your DNS Hosts File

Read Article

How to Edit Your DNS Hosts File

Read Article

Microsoft Exchange Server Security Update

Read Article

How to Monitor Your Server in WHM

Read Article

How to Monitor Your Server in WHM

Read Article