GitHub Cheat Sheet

A collection of cool hidden and not so hidden features of Git and GitHub. This cheat sheet was inspired by Zach Holman's Git and GitHub Secrets talk at Aloha Ruby Conference 2012 (slides) and his More Git and GitHub Secrets talk at WDCNZ 2013 (slides).


Read this in other languages: English, 한국어, 日本語, 简体中文.

Table of Contents


Ignore Whitespace

Adding ?w=1 to any diff URL will remove any changes only in whitespace, enabling you to see only that code that has changed.

Diff without whitespace

Read more about GitHub secrets.

Adjust Tab Space

Adding ?ts=4 to a diff or file URL will display tab characters as 4 spaces wide instead of the default 8. The number after ts can be adjusted to suit your preference. This does not work on Gists, or raw file views.

Here is a Go source file before adding ?ts=4:

Before, tab space example

...and this is after adding ?ts=4:

After, tab space example

Commit History by Author

To view all commits on a repo by author add ?author=username to the URL.

DHH commit history

Read more about the differences between commits views.

Cloning a Repository

When cloning a repository the .git can be left off the end.

$ git clone

Read more about the Git clone command.

Compare all Branches to Another Branch

If you go to the repo's Branches page, next to the Commits button:{user}/{repo}/branches

... you would see a list of all branches which are not merged into the main branch.

From here you can access the compare page or delete a branch with a click of a button.

Compare branches not merged into master in jquery/jquery repo -

However, often you need to compare branches to a branch other than master (e.g. development). To do this, append the URL with the name of the branch like so:{user}/{repo}/branches/{branch}

Compare branches not merged into `1.x-master` in jquery/jquery repo -

To see the merged branches, append ?merged=1 to the URL.

Compare branches merged in to `1.x-master` in jquery/jquery repo -

This view allows you to delete branches easily from the page, without using the command-line.

Comparing Branches

To use GitHub to compare branches, change the URL to look like this:{range}

Where {range} = master...4-1-stable

For example:

Rails branch compare example

{range} can be changed to things like:[email protected]{}...master[email protected]{2014-10-04}...master

Dates are in the format YYYY-DD-MM

Another compare example

...which allows you to see the difference on the master branch up a set time ago or a specified date.

Read more about comparing commits across time.

Compare Branches across Forked Repositories

To use GitHub to compare branches across forked repositories, change the URL to look like this:{foreign-user}:{branch}...{own-branch}

For example:

Forked branch compare


Gists are an easy way to work with small bits of code without creating a fully fledged repository.


Add .pibb to the end of any Gist URL (like this) in order to get the HTML only version suitable for embedding in any other site.

Gists can be treated as a full repository so they can be cloned like any other:

$ git clone


Read more about creating gists. is a simple URL shortener for GitHub.

You can also use it via pure HTTP using Curl:

$ curl -i -F "url="
HTTP/1.1 201 Created

$ curl -i
HTTP/1.1 302 Found

Read more about

Keyboard Shortcuts

When on a repository page, keyboard shortcuts allow you to navigate easily.

  • Pressing t will bring up a file explorer.
  • Pressing w will bring up the branch selector.
  • Pressing s will select the Command Bar.
  • Pressing l will edit labels on existing Issues.
  • Pressing y when looking at a file (e.g. will change your URL to one which, in effect, freezes the page you are looking at. If this code changes, you will still be able to see what you saw at that current time.

To see all of the shortcuts for the current page press ?:

Keyboard shortcuts

Read more about using the Command Bar.

Line Highlighting in Repositories

Either adding #L52 to the end of a code file URL or simply clicking the line number will highlight that line number.

It also works with ranges, e.g. #L53-L60, to select ranges, hold shift and click two lines:

Line Highlighting

Closing Issues via Commit Messages

If a particular commit fixes an issue, any of the keywords fix/fixes/fixed, close/closes/closed or resolve/resolves/resolved, followed by the issue number, will close the issue once it is committed to the master branch.

$ git commit -m "Fix screwup, fixes #12"

This closes the issue and references the closing commit.

Closing Repo

Read more about closing Issues via commit messages.

If you want to link to another issue in the same repository, simple type hash # then the issue number, it will be auto-linked.

To link to an issue in another repository, user_name/repo_name#ISSUE_NUMBER e.g. tiimgreen/toc#12.

Cross-Link Issues

CI Status on Pull Requests

If set up correctly, every time you receive a Pull Request, Travis CI will build that Pull Request just like it would every time you make a new commit. Read more about how to get started with Travis CI.

Travis CI status

Read more about the commit status API.

Syntax Highlighting in Markdown Files

For example, to syntax highlight Ruby code in your Markdown files write:

require 'tabbit'
table ='Name', 'Email')
table.add_row('Tim Green', '[email protected]')
puts table.to_s

This will produce:

require 'tabbit'
table ='Name', 'Email')
table.add_row('Tim Green', '[email protected]')
puts table.to_s

GitHub uses Linguist to perform language detection and syntax highlighting. You can find out which keywords are valid by perusing the languages YAML file.

Read more about GitHub Flavored Markdown.


Emojis can added to on Pull Requests, Issues, commit messages, Markdown files, etc. using :name_of_emoji::


Would produce:


The full list of supported Emojis on GitHub can be found at or scotch-io/All-Github-Emoji-Icons.

The top 5 used Ejmojis on GitHub are:

  1. :shipit: - :shipit:
  2. :sparkles: - :sparkles:
  3. :-1: - :-1:
  4. :+1: - :+1:
  5. :clap: - :clap:


Images and GIFs can be added to comments, READMEs etc.:

![Alt Text](

Peter don't care

All images are cached on GitHub, so if your host goes down, the image will remain available.

Embedding Images in GitHub Wiki

There are multiple ways of embedding images in Wiki pages. There's the standard Markdown syntax (shown above). But there's also a syntax that allows things like specifying the height or width of the image:

[[ | height = 100px ]]

Which produces:

Just a screenshot

Quick Quoting

When on a comment thread and you want to quote something someone previously said, highlight the text and press r, this will copy it into your text box in the block-quote format.

Quick Quote

Read more about quick quoting.

Quick Licensing

When creating a repository GitHub gives you the options of adding in a pre-made license:


You can also add them to existing repositories by creating a new file through the web interface. When the name LICENSE is typed in you will get an option to use a template:


Also works for .gitignore.

Read more about open source licensing.

Task Lists

In Issues and Pull requests check boxes can be added with the following syntax (notice the space):

- [ ] Be awesome
- [ ] Prepare dinner
  - [ ] Research recipe
  - [ ] Buy ingredients
  - [ ] Cook recipe
- [ ] Sleep

Task List

When they are clicked, they will be updated in the pure Markdown:

- [x] Be awesome
- [ ] Prepare dinner
  - [x] Research recipe
  - [x] Buy ingredients
  - [ ] Cook recipe
- [ ] Sleep

Read more about task lists.

Task Lists in Markdown Documents

In full Markdown documents read-only checklists can now be added using the following syntax:

- [ ] Mercury
- [x] Venus
- [x] Earth
  - [x] Moon
- [x] Mars
  - [ ] Deimos
  - [ ] Phobos

Read more about task lists in markdown documents.

Relative links are recommended in your Markdown files when linking to internal content.

[Link to a header](#awesome-section)
[Link to a file](docs/readme)

Absolute links have to be updated whenever the URL changes (e.g. repository renamed, username changed, project forked). Using relative links makes your documentation easily stand on its own.

Read more about relative links.

Metadata and Plugin Support for GitHub Pages

Within Jekyll pages and posts, repository information is available within the site.github namespace, and can be displayed, for example, using {{ site.github.project_title }}.

The Jemoji and jekyll-mentions plugins enable emoji and @mentions in your Jekyll posts and pages to work just like you'd expect when interacting with a repository on

Read more about repository metadata and plugin support for GitHub Pages.

Viewing YAML Metadata in your Documents

Many blogging websites, like Jekyll with GitHub Pages, depend on some YAML-formatted metadata at the beginning of your post. GitHub will render this metadata as a horizontal table, for easier reading

YAML metadata

Read more about viewing YAML metadata in your documents.

Rendering Tabular Data

GitHub supports rendering tabular data in the form of .csv (comma-separated) and .tsv (tab-separated) files.

Tabular data

Read more about rendering tabular data.


Rendered Prose Diffs

Commits and pull requests including rendered documents supported by GitHub (e.g. Markdown) feature source and rendered views.

Source / Rendered view

Click the "rendered" button to see the changes as they'll appear in the rendered document. Rendered prose view is handy when you're adding, removing, and editing text:

Rendered Prose Diffs

Read more about rendered prose diffs.

Diffable Maps

Any time you view a commit or pull request on GitHub that includes geodata, GitHub will render a visual representation of what was changed.

Diffable Maps

Read more about diffable maps.

Expanding Context in Diffs

Using the unfold button in the gutter of a diff, you can reveal additional lines of context with a click. You can keep clicking unfold until you've revealed the whole file, and the feature is available anywhere GitHub renders diffs.

Expanding Context in Diffs

Read more about expanding context in diffs.

Diff or Patch of Pull Request

You can get the diff of a Pull Request by adding a .diff or .patch extension to the end of the URL. For example:

The .diff extension would give you this in plain text:

diff --git a/ b/
index 88fcf69..8614873 100644
--- a/
+++ b/
@@ -28,6 +28,7 @@ All the hidden and not hidden features of Git and GitHub. This cheat sheet was i
 - [Merged Branches](#merged-branches)
 - [Quick Licensing](#quick-licensing)
 - [TODO Lists](#todo-lists)
+- [Relative Links](#relative-links)
 - [.gitconfig Recommendations](#gitconfig-recommendations)
     - [Aliases](#aliases)
     - [Auto-correct](#auto-correct)
@@ -381,6 +382,19 @@ When they are clicked, they will be updated in the pure Markdown:
 - [ ] Sleep


Rendering and diffing images

GitHub can display several common image formats, including PNG, JPG, GIF, and PSD. In addition, there are several ways to compare differences between versions of those image formats.

Diffable PSD

Read more about rendering and diffing images.


Hub is a command line Git wrapper that gives you extra features and commands that make working with GitHub easier.

This allows you to do things like:

$ hub clone tiimgreen/toc

Check out some more cool commands Hub has to offer.

Decreasing Contributor Friction

If you want people to use and contribute to your project, you need to start by answering their most basic questions. What does the project do? How do I use it? How am I allowed to use it? How do I contribute? How do I get up and running in development? How do I make sure my new features didn't break old functionality?

Friction is a command line script that will check your project for common answers to these questions. This is some example output:

Friction output

Friction supports MRI 2.1.0, MRI 2.0.0, and MRI 1.9.3.

Contributing Guidelines

Adding a CONTRIBUTING file to the root of your repository will add a link to your file when a contributor creates an Issue or opens a Pull Request.

Contributing Guidelines

Read more about contributing guidelines.

GitHub Resources

Title Link
GitHub Explore
GitHub Blog
GitHub Help
GitHub Training
GitHub Developer

GitHub Talks

Title Link
How GitHub Uses GitHub to Build GitHub
Introduction to Git with Scott Chacon of GitHub
How GitHub No Longer Works
Git and GitHub Secrets
More Git and GitHub Secrets


Previous Branch

To move to the previous branch in Git:

$ git checkout -
# Switched to branch 'master'

$ git checkout -
# Switched to branch 'next'

$ git checkout -
# Switched to branch 'master'

Read more about Git branching.


Git Stripspace:

  • Strips trailing whitespace
  • Collapses newlines
  • Adds newline to end of file

A file must be passed when calling the command, e.g.:

$ git stripspace <

Read more about the Git stripspace command.

Checking out Pull Requests

Pull Requests are special branches on the GitHub repository which can be retrieved locally in several ways:

Retrieve a specific Pull Request and store it temporarily in FETCH_HEAD for quickly diffing or mergeing:

$ git fetch origin refs/pull/[PR-Number]/head

Acquire all Pull Request branches as local remote branches by refspec:

$ git fetch origin '+refs/pull/*/head:refs/remotes/origin/pr/*'

Or setup the remote to fetch Pull Requests automatically by adding these corresponding lines in your repository's .git/config:

[remote "origin"]
    fetch = +refs/heads/*:refs/remotes/origin/*
    url = [email protected]:tiimgreen/github-cheat-sheet.git
[remote "origin"]
    fetch = +refs/heads/*:refs/remotes/origin/*
    url = [email protected]:tiimgreen/github-cheat-sheet.git
    fetch = +refs/pull/*/head:refs/remotes/origin/pr/*

For Fork-based Pull Request contributions, it's useful to checkout a remote branch representing the Pull Request and create a local branch from it:

$ git checkout pr/42 pr-42

Read more about checking out pull requests locally.

Empty Commits :trollface:

Commits can be pushed with no code changes by adding --allow-empty:

$ git commit -m "Big-ass commit" --allow-empty

Some use-cases for this (that make sense), include:

  • Annotating the start of a new bulk of work or a new feature.
  • Documenting when you make changes to the project that aren't code related.
  • Communicating with people using your repository.
  • The first commit of a repo, as the first commit cannot be rebased later: git commit -m "init repo" --allow-empty.

Styled Git Status


$ git status


git status

By adding -sb:

$ git status -sb

This is produced:

git status -sb

Read more about the Git status command.

Styled Git Log


$ git log --all --graph --pretty=format:'%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative


git log --all --graph --pretty=format:'%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative

Credit to Palesz

This can be aliased using the instructions found here.

Read more about the Git log command.

Git Query

A Git query allows you to search all your previous commit messages and find the most recent one matching the query.

$ git show :/query

Where query (case-sensitive) is the term you want to search, this then finds the last one and gives details on the lines that were changed.

$ git show :/typo

git show :/query

Press q to quit.

Merged Branches


$ git branch --merged

Will give you a list of all branches that have been merged into your current branch.


$ git branch --no-merged

Will give you a list of branches that have not been merged into your current branch.

Read more about the Git branch command.

Web Server for Browsing Local Repositories

Use the Git instaweb command to instantly browse your working repository in gitweb. This command is a simple script to set up gitweb and a web server for browsing the local repository.

$ git instaweb


Git instaweb

Read more about the Git instaweb command.

Git Configurations

Your .gitconfig file contains all your Git configurations.


Aliases are helpers that let you define your own git calls. For example you could set git a to run git add --all.

To add an alias, either navigate to ~/.gitconfig and fill it out in the following format:

  co = checkout
  cm = commit
  p = push
  # Show verbose output about tags, branches or remotes
  tags = tag -l
  branches = branch -a
  remotes = remote -v

...or type in the command-line:

$ git config --global alias.new_alias git_function

For example:

$ git config --global commit

For an alias with multiple functions use quotes:

$ git config --global 'add -A . && commit'

Some useful aliases include:

Alias Command What to Type
git cm git commit git config --global commit
git co git checkout git config --global checkout
git ac git add . -A git commit git config --global '!git add -A && git commit'
git st git status -sb git config --global 'status -sb'
git tags git tag -l git config --global alias.tags 'tag -l'
git branches git branch -a git config --global alias.branches 'branch -a'
git remotes git remote -v git config --global alias.remotes 'remote -v'
git lg git log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit -- git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --"

Some Aliases are taken from @mathiasbynens dotfiles:


If you type git comit you will get this:

$ git comit -m "Message"
# git: 'comit' is not a git command. See 'git --help'.

# Did you mean this?
#   commit

To call commit when comit is typed, just enable auto-correct:

$ git config --global help.autocorrect 1

So now you will get this:

$ git comit -m "Message"
# WARNING: You called a Git command named 'comit', which does not exist.
# Continuing under the assumption that you meant 'commit'
# in 0.1 seconds automatically...


To add more color to your Git output:

$ git config --global color.ui 1

Read more about the Git config command.

Git Resources

Title Link
Official Git Site
Official Git Video Tutorials
Code School Try Git
Introductory Reference & Tutorial for Git
Official Git Tutorial
Everyday Git
Git Immersion
Ry's Git Tutorial
Git for Designer
Git for Computer Scientists
Git Magic
GitHub Training Kit

Git Books

Title Link
Pragmatic Version Control Using Git
Pro Git
Git Internals Peepcode
Git in the Trenches
Version Control with Git
Pragmatic Guide to Git
Git: Version Control for Everyone