AlexStelm / github-cheat-sheet

Cool features of GitHub

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

GitHub Cheat Sheet

All the hidden and not 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).


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.

Cloning a Repo

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

$ git clone

Hub - Git Wrapper

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

This allows you to do things like:

$ hub clone tiimgreen/toc

instead of:

$ git clone

Previous Branch

To move to the previous directory in the command line:

$ cd -

Similarly, to move to the last branch in git:

$ git checkout -
# Switched to branch 'master'

$ git checkout -
# Switched to branch 'next'

$ git checkout -
# Switched to branch 'master' is a simple URL shortener for GitHub.


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

Although, Gists can be treated as a full repo so they can be cloned like any other:

$ git clone


Keyboard Shortcuts

When on a repo 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 search bar.

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 ?.

Closing Issues with Commits

If a particular commit fixes an issue, any of the keywords fix/fixes/fixed or close/closes/closed, followed by the issue number, will close the issue.

$ git commit -m "Fix cock up, fixes #12"

This closes the issue and references the closing commit.

Closing Repo

Checking out Pull Requests

If you want to check out pull request locally, you can fetch it using that command:

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

then, checkout Pull Request (i.e. 42) using

$ git checkout refs/pull/42

Alternatively, you can fetch them as remote branches:

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

and checkout as:

$ git checkout origin/pr/42

and even fetch them automatically, if you add corresponding lines in your .git/config:

[remote "origin"]
    fetch = +refs/heads/*:refs/remotes/origin/*
    url =
[remote "origin"]
    fetch = +refs/heads/*:refs/remotes/origin/*
    url =
    fetch = +refs/pull/*/head:refs/remotes/origin/pr/*

Cross-link Issues

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

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

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', '')
puts table.to_s

This will produce:

require 'tabbit'
table ='Name', 'Email')
table.add_row('Tim Green', '')
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.

Commit History by Author

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

Empty Commits

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

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


Comparing Branches

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

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


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

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

Line Highlighting in Repos

Either adding #L52 to the end of a code file URL or simply clicking the lin 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


Emojis can be generated on Pull Requests, Issues, Commit Messages, READMEs, etc. using :name_of_emoji:


πŸ˜„ πŸ’© :shipit: πŸ‘

The full list of supported Emojis on GitHub can be found here or here.

The top 5 used Ejmojis on GitHub are:

  1. :shipit: :shipit:
  2. ✨ :sparkles:
  3. πŸ‘Ž :-1:
  4. πŸ‘ :+1:
  5. πŸ‘ :clap:


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

![Alt Text](

Chuck Norris

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

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

Styled Git Status

$ git status

git status

Can be changed to:

$ git status -sb

git status -sb

Styled Git Log

$ git log --all --graph --decorate --oneline --abbrev-commit

git log --all --graph --decorate --oneline --abbrev-commit

NOTE: This can be added into an Alias (shorter command) using the instructions here

Git Query

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

$ git show :/query

Where query 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

NOTE: 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.

Quick Licensing

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


You can also add them to existing repos 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.

TODO Lists

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

- [ ] Be awesome
- [ ] Do stuff
- [ ] Sleep


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

- [x] Be awesome
- [x] Do stuff
- [ ] Sleep

.gitconfig Recommendations

Your .gitconfig is the file that contains all your preferences.


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

or type in the command line:

$ git config alias.new_alias git_function


$ git config commit

NOTE: for an alias with multiple functions use quotes:

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

Some recommendations include:

Alias Current 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'


Currently if you type git comit you will get this result:

$ 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 autocorrect:

$ git config --global help.autocorrect 1

So now you will get this result:

$ 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 colour to your git command line:

$ git config --global color.ui 1


Share on Twitter


Cool features of GitHub

License:MIT License