Git & GitHub - GitHub Gists
How to create and manage gists on GitHub
GitHub Gists are a simple way to share code snippets, notes, and other short pieces of information. They can be public or secret, and you can manage them directly from your GitHub account. This guide explains how to create and manage gists on GitHub.
Key Points:
- Gists are useful for sharing code snippets, notes, and more.
- You can create public or secret gists depending on your sharing preferences.
- Gists support versioning, comments, and embedding in other websites.
Creating a Gist
Step 1: Navigate to the Gists Page
Go to the GitHub Gists page by clicking on your profile picture in the top-right corner and selecting "Your gists" or by visiting https://gist.github.com.
Step 2: Create a New Gist
Click on the "New gist" button in the top-right corner of the page.

Step 3: Fill Out the Gist Form
Fill out the form with the following details:
- Filename including extension: Enter the name of your file, including the extension (e.g.,
example.js
). - Description: Add a brief description of the gist.
- Content: Enter the code or text you want to share.
- Public or Secret: Choose whether the gist is public or secret.

Once you've filled out the form, click "Create secret gist" or "Create public gist" to create your gist.
Managing Gists
Editing a Gist
To edit a gist, navigate to the gist page and click the "Edit" button. Make your changes and click "Update gist" to save them.

Deleting a Gist
To delete a gist, navigate to the gist page and click the "Delete" button. Confirm the deletion to remove the gist.

Commenting on Gists
Gists support comments, allowing you to discuss the content with others. To add a comment, navigate to the gist page, enter your comment in the comment box, and click "Comment."

Embedding Gists
You can embed gists in other websites by copying the embed code provided on the gist page. Click the "Embed" button on the gist page and copy the provided HTML code to embed the gist in your website or blog.

Using Gists with Git
You can clone, edit, and push changes to gists using Git. To clone a gist, use the following command:
# Clone a gist
$ git clone https://gist.github.com/username/gist-id.git
Make changes to the cloned gist locally, then commit and push your changes:
# Make changes and commit
$ git add .
$ git commit -m "Update gist"
# Push changes
$ git push origin main
Summary
This guide covered how to create and manage gists on GitHub, including creating, editing, deleting, and commenting on gists. Additionally, it explained how to embed gists in other websites and use Git to manage gists. GitHub Gists are a powerful tool for sharing and collaborating on code snippets and notes.