12 KiB
GitHub Gists Guide
Overview
GitHub Gists provide a simple way to share code snippets, notes, and other text content with others. Every gist is a Git repository, which means it can be forked, cloned, and versioned just like a regular repository.
What are Gists?
Gists are useful for:
- Sharing code snippets quickly
- Creating simple documentation
- Storing configuration files
- Embedding code examples in blogs or websites
- Collaborating on small pieces of code
- Creating quick demos or examples
- Saving command-line scripts
Types of Gists
Public Gists
- Visible to everyone and searchable
- Show up in GitHub's Discover section
- Can be found through search engines
- Good for sharing examples you want others to find
Secret Gists
- Not searchable or discoverable (unless you're logged in and are the author)
- Anyone with the URL can view the gist
- Not truly private - if someone discovers the URL, they can see it
- Good for sharing with specific people via direct link
- For truly private code, use a private repository instead
Important: GitHub automatically scans secret gists for leaked secrets (API keys, passwords, etc.) and notifies the relevant partners if detected.
Creating a Gist
Method 1: Via GitHub Website
-
Sign in to your GitHub account
-
Navigate to your gist home page: https://gist.github.com/
-
Click the "+" icon in the top right corner
-
Fill in the gist details:
- Gist description (optional): A brief description of what the gist contains
- Filename including extension: Give your file a name with the appropriate extension (e.g.,
script.py,config.json,notes.md) - File contents: Paste or type your code/content
-
Add more files (optional): Click "Add file" to include multiple files in one gist
-
Choose visibility:
- Click "Create secret gist" for a secret gist (default)
- Or click the dropdown and select "Create public gist"
Method 2: Via GitHub CLI
You can also create gists using the GitHub CLI (gh):
# Create a public gist from a file
gh gist create myfile.py --public
# Create a secret gist from a file
gh gist create myfile.py
# Create a gist from stdin
echo "print('Hello, World!')" | gh gist create --filename hello.py
# Create a gist with description
gh gist create myfile.py --desc "My awesome Python script"
# Create a multi-file gist
gh gist create file1.py file2.py file3.py
For more information, see gh gist create in the GitHub CLI documentation.
Method 3: Drag and Drop
You can drag and drop a text file from your desktop directly into the gist editor on the GitHub website.
Managing Your Gists
Viewing Your Gists
- Go to https://gist.github.com/
- Click your profile picture in the top right
- Select "Your gists" to see all your gists
Or visit: https://gist.github.com/[your-username]
Editing a Gist
- Navigate to the gist you want to edit
- Click the "Edit" button in the top right
- Make your changes
- Click "Update secret gist" or "Update public gist"
Deleting a Gist
- Navigate to the gist you want to delete
- Click the "Delete" button in the top right
- Confirm the deletion
Note: Deleting a gist cannot be undone.
Making a Secret Gist Public
Secret gists can be converted to public gists:
- Open the secret gist
- Click "Edit"
- Change the visibility to public
- Save the changes
Note: You cannot convert a public gist to secret.
Advanced Gist Features
Viewing Commit History
Since gists are Git repositories:
- Click the "Revisions" tab on any gist
- View the full commit history with diffs
- Click any revision to see what changed
Forking Gists
To create your own copy of someone else's gist:
- Open the gist you want to fork
- Click the "Fork" button in the top right
- You now have your own copy to modify
Cloning Gists
Clone a gist to your local machine:
# Clone via HTTPS
git clone https://gist.github.com/[gist-id].git
# Clone via SSH
git clone git@gist.github.com:[gist-id].git
# Example
git clone https://gist.github.com/123abc456def.git my-gist
cd my-gist
Starring Gists
To save gists you find useful:
- Open the gist
- Click the "Star" button
- View your starred gists at:
https://gist.github.com/[username]/starred
Embedding Gists
Embed gists in websites, blogs, or documentation:
- Open the gist
- Click the "Embed" button
- Copy the embed code (JavaScript snippet)
- Paste into your HTML
<script src="https://gist.github.com/[username]/[gist-id].js"></script>
To embed a specific file from a multi-file gist:
<script src="https://gist.github.com/[username]/[gist-id].js?file=filename.ext"></script>
Downloading Gists
Download a gist as a ZIP file:
- Open the gist
- Click "Download ZIP" in the top right
Or download via command line:
# Using GitHub CLI
gh gist view [gist-id] > myfile.py
# Using wget
wget https://gist.githubusercontent.com/[username]/[gist-id]/raw/[commit-hash]/[filename]
# Using curl
curl https://gist.githubusercontent.com/[username]/[gist-id]/raw/[filename]
Subscribing to Gists
Receive notifications about gist updates:
- Open the gist
- Click "Subscribe" at the top
- You'll be notified when the gist is updated or someone comments
Notifications
You'll receive notifications when:
- You are the author of a gist
- Someone mentions you in a gist comment
- You subscribe to a gist
Special Features
GeoJSON Mapping
Gists support GeoJSON files and will display them as interactive maps:
- Create a gist with a
.geojsonfile - GitHub will automatically render it as a map
Syntax Highlighting
Gists automatically apply syntax highlighting based on file extension:
.py- Python.js- JavaScript.mq5- MQL5 (MetaQuotes Language).json- JSON.yamlor.yml- YAML- And many more...
Using Gists with GitHub CLI
The GitHub CLI provides powerful gist management:
# List your gists
gh gist list
# View a gist
gh gist view [gist-id]
# Edit a gist
gh gist edit [gist-id]
# Delete a gist
gh gist delete [gist-id]
# Clone a gist
gh gist clone [gist-id]
Practical Examples for This Project
Example 1: Share MQL5 Strategy Snippet
Create a gist to share a small MQL5 trading strategy:
//+------------------------------------------------------------------+
//| Quick SMC BOS Detection Snippet |
//+------------------------------------------------------------------+
bool DetectBOS(double currentHigh, double currentLow,
double prevHigh, double prevLow)
{
// Bullish BOS: current high breaks previous high
if(currentHigh > prevHigh)
return true;
// Bearish BOS: current low breaks previous low
if(currentLow < prevLow)
return true;
return false;
}
Save as: smc_bos_detection.mq5
Description: "Quick Break of Structure (BOS) detection for MQL5"
Example 2: Share Configuration File
Share your MT5 startup configuration:
{
"mt5_path": "C:\\Program Files\\MetaTrader 5\\terminal64.exe",
"auto_login": true,
"enable_alerts": true,
"risk_percent": 1.0,
"max_positions": 3
}
Save as: mt5_config.json
Description: "MT5 startup configuration template"
Example 3: Share Automation Script
Share a useful automation script:
#!/bin/bash
# Quick MT5 deployment helper
MT5_DATA_FOLDER="$1"
if [ -z "$MT5_DATA_FOLDER" ]; then
echo "Usage: $0 <MT5_DATA_FOLDER>"
exit 1
fi
echo "Deploying to: $MT5_DATA_FOLDER"
cp -v mt5/MQL5/Indicators/*.mq5 "$MT5_DATA_FOLDER/MQL5/Indicators/"
cp -v mt5/MQL5/Experts/*.mq5 "$MT5_DATA_FOLDER/MQL5/Experts/"
echo "Deployment complete!"
Save as: quick_deploy.sh
Description: "Quick MT5 indicator and EA deployment script"
Discovering Public Gists
Find useful gists created by others:
- All Gists: Visit gist.github.com and click "All Gists"
- Discover: Browse gist.github.com/discover for featured gists
- Search: Use Gist Search to find specific content
- By Language: Filter gists by programming language
Pinning Gists to Your Profile
You can pin gists to your GitHub profile:
- Go to your GitHub profile page
- Click "Customize your pins"
- Select gists you want to showcase
- Rearrange them as desired
Pinned gists appear alongside pinned repositories on your profile.
Best Practices
- Use Descriptive Names: Give your files meaningful names with proper extensions
- Add Descriptions: Help others understand what your gist contains
- Keep It Focused: Each gist should contain related files for a single purpose
- Use Comments: Add comments to explain complex code
- Update Rather Than Delete: Edit existing gists instead of creating duplicates
- Choose Visibility Wisely: Use secret for drafts, public for sharing
- Version Control: Gists maintain history, so don't be afraid to update them
- No Secrets: Never put passwords, API keys, or sensitive data in gists (even secret ones)
Common Use Cases
For Traders and Developers
- Share Trading Signals: Post formatted market analysis or trade ideas
- Configuration Snippets: Share EA settings or indicator parameters
- Helper Functions: Share reusable MQL5 functions
- Installation Instructions: Create step-by-step guides
- Troubleshooting Notes: Document solutions to common problems
- Script Collections: Organize related automation scripts
- API Examples: Show how to integrate with trading APIs
Gists vs Repositories
| Feature | Gists | Repositories |
|---|---|---|
| Purpose | Small snippets | Full projects |
| Size | Best for small files | Any size |
| Visibility | Public or Secret | Public, Private, or Internal |
| Issues/PRs | No | Yes |
| Projects | No | Yes |
| Wiki | No | Yes |
| Releases | No | Yes |
| Complexity | Simple | Full-featured |
Use Gists when: You want to quickly share small snippets or notes Use Repositories when: You're building a full project with multiple collaborators
GitHub CLI Reference
Quick reference for common gist operations:
# Create
gh gist create file.py --public --desc "Description"
# List
gh gist list --limit 10
gh gist list --public
gh gist list --secret
# View
gh gist view [gist-id]
gh gist view [gist-id] --web # Open in browser
gh gist view [gist-id] --files # List files
# Edit
gh gist edit [gist-id]
gh gist edit [gist-id] --add file.py # Add file
gh gist edit [gist-id] --remove file.py # Remove file
# Delete
gh gist delete [gist-id]
# Clone
gh gist clone [gist-id] [directory]
Resources
Troubleshooting
Q: My gist isn't showing syntax highlighting
- Make sure you've included the correct file extension
- Some languages may not be supported
Q: Can I make a public gist private?
- No, you can only convert secret gists to public, not the reverse
- For private code, use a private repository
Q: How do I delete all my gists at once?
- There's no bulk delete feature
- You can use the GitHub API or CLI to automate deletion if needed
Q: Can I password-protect a gist?
- No, gists cannot be password-protected
- Use a private repository for sensitive content
Q: Is there a size limit for gists?
- Individual files should be reasonable in size
- For large files, use a repository instead
Next Steps:
- Create your first gist with a useful code snippet
- Explore the GitHub Profile README Guide to showcase your work
- Check out the GitHub CLI Setup Guide for command-line gist management