[[
wikihub
]]
Search
⌘K
Explore
People
For Agents
Sign in
Explore
People
For Agents
Sign in
@harrisonqian / Awesome / wiki/development-environment/cheat-sheet.md
Suggest edit
Cancel
Submit suggestion
Title
Name
Note
--- visibility: public --- # Cheat Sheet **repo:** [tiimgreen/github-cheat-sheet](https://github.com/tiimgreen/github-cheat-sheet) **category:** [[development-environment|Development Environment]] --- # GitHub Cheat Sheet [](https://github.com/sindresorhus/awesome) A collection of cool hidden and not so hidden features of Git and GitHub. This cheat sheet was inspired by [Zach Holman](https://github.com/holman)'s [Git and GitHub Secrets](http://confreaks.tv/videos/aloharuby2012-git-and-github-secrets) talk at Aloha Ruby Conference 2012 ([slides](https://speakerdeck.com/holman/git-and-github-secrets)) and his [More Git and GitHub Secrets](https://vimeo.com/72955426) talk at WDCNZ 2013 ([slides](https://speakerdeck.com/holman/more-git-and-github-secrets)). *Shortlink: [`http://git.io/sheet`](http://git.io/sheet)* *Read this in other languages: [English](README.md), [한국어](README.ko.md), [日本語](README.ja.md), [简体中文](README.zh-cn.md), [正體中文](README.zh-tw.md).* GitHub Cheat Sheet is sponsored by [Snapshot: create interactive professional-quality product photos using AI](https://www.snapshotapp.io/) ## Table of Contents - [GitHub](#github) - [Ignore Whitespace](#ignore-whitespace) - [Adjust Tab Space](#adjust-tab-space) - [Commit History by Author](#commit-history-by-author) - [Cloning a Repository](#cloning-a-repository) - [Branch](#branch) - [Compare all Branches to Another Branch](#compare-all-branches-to-another-branch) - [Comparing Branches](#comparing-branches) - [Compare Branches across Forked Repositories](#compare-branches-across-forked-repositories) - [Gists](#gists) - [Git.io](#gitio) - [Keyboard Shortcuts](#keyboard-shortcuts) - [Line Highlighting in Repositories](#line-highlighting-in-repositories) - [Closing Issues via Commit Messages](#closing-issues-via-commit-messages) - [Cross-Link Issues](#cross-link-issues) - [Locking Conversations](#locking-conversations) - [CI Status on Pull Requests](#ci-status-on-pull-requests) - [Filters](#filters) - [Syntax Highlighting in [Markdown](/@harrisonqian/awesome/wiki/miscellaneous/markdown) Files](#syntax-highlighting-in-markdown-files) - [Emojis](#emojis) - [Images/GIFs](#imagesgifs) - [Embedding Images in [GitHub](/@harrisonqian/awesome/wiki/development-environment/github) Wiki](#embedding-images-in-github-wiki) - [Quick Quoting](#quick-quoting) - [Pasting Clipboard Image to Comments](#pasting-clipboard-image-to-comments) - [Quick Licensing](#quick-licensing) - [Task Lists](#task-lists) - [Task Lists in [Markdown](/@harrisonqian/awesome/wiki/miscellaneous/markdown) Documents](#task-lists-in-markdown-documents) - [Relative Links](#relative-links) - [Metadata and Plugin Support for [GitHub](/@harrisonqian/awesome/wiki/development-environment/github) Pages](#metadata-and-plugin-support-for-github-pages) - [Viewing YAML Metadata in your Documents](#viewing-yaml-metadata-in-your-documents) - [Rendering Tabular Data](#rendering-tabular-data) - [Rendering PDF](#rendering-pdf) - [Revert a Pull Request](#revert-a-pull-request) - [Diffs](#diffs) - [Rendered Prose Diffs](#rendered-prose-diffs) - [Diffable Maps](#diffable-maps) - [Expanding Context in Diffs](#expanding-context-in-diffs) - [Diff or Patch of Pull Request](#diff-or-patch-of-pull-request) - [Rendering and diffing images](#rendering-and-diffing-images) - [Hub](#hub) - [Contribution Guidelines](#contribution-guidelines) - [CONTRIBUTING file](#contributing-file) - [ISSUE_TEMPLATE file](#issue_template-file) - [PULL_REQUEST_TEMPLATE file](#pull_request_template-file) - [Octicons](#octicons) - [GitHub Student Developer Pack](#[github](/@harrisonqian/awesome/wiki/development-environment/github)-student-developer-pack) - [GitHub Resources](#[github](/@harrisonqian/awesome/wiki/development-environment/github)-resources) - [GitHub Talks](#[github](/@harrisonqian/awesome/wiki/development-environment/github)-talks) - [SSH keys](#ssh-keys) - [Profile Image](#profile-image) - [Repository Templates](#repository-templates) - [Git](#git) - [Remove All Deleted Files from the Working Tree](#remove-all-deleted-files-from-the-working-tree) - [Previous Branch](#previous-branch) - [Stripspace](#stripspace) - [Checking out Pull Requests](#checking-out-pull-requests) - [Empty Commits](#empty-commits) - [Styled Git Status](#styled-git-status) - [Styled Git Log](#styled-git-log) - [Git Query](#git-query) - [Git Grep](#git-grep) - [Merged Branches](#merged-branches) - [Fixup and Autosquash](#fixup-and-autosquash) - [Web Server for Browsing Local Repositories](#web-server-for-browsing-local-repositories) - [Git Configurations](#git-configurations) - [Aliases](#aliases) - [Auto-Correct](#auto-correct) - [Color](#color) - [Git Resources](#git-resources) - [Git Books](#git-books) - [Git Videos](#git-videos) - [Git Articles](#git-articles) ## GitHub ### Ignore Whitespace Adding `?w=1` to any diff URL will remove any changes only in whitespace, enabling you to see only the code that has changed.  [*Read more about GitHub secrets.*](https://github.com/blog/967-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, but a [Chrome extension](https://chrome.google.com/webstore/detail/tab-size-on-github/ofjbgncegkdemndciafljngjbdpfmbkn) can automate this. Here is a Go source file before adding `?ts=4`:  ...and this is after adding `?ts=4`:  ### Commit History by Author To view all commits on a repo by author add `?author={user}` to the URL. ``` https://github.com/rails/rails/commits/master?author=dhh ```  [*Read more about the differences between commits views.*](https://help.github.com/articles/differences-between-commit-views/) ### Cloning a Repository When cloning a repository the `.git` can be left off the end. ```bash $ git clone https://github.com/tiimgreen/github-cheat-sheet ``` [*Read more about the Git `clone` command.*](http://git-scm.com/docs/git-clone) ### Branch #### Compare all Branches to Another Branch If you go to the repo's [Branches](https://github.com/tiimgreen/github-cheat-sheet/branches) page, next to the Commits button: ``` https://github.com/{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.  #### Comparing Branches To use GitHub to compare branches, change the URL to look like this: ``` https://github.com/{user}/{repo}/compare/{range} ``` where `{range} = master...4-1-stable` For example: ``` https://github.com/rails/rails/compare/master...4-1-stable ```  `{range}` can be changed to things like: ``` https://github.com/rails/rails/compare/master@{1.day.ago}...master https://github.com/rails/rails/compare/master@{2014-10-04}...master ``` *Here, dates are in the format `YYYY-MM-DD`*  Branches can also be compared in `diff` and `patch` views: ``` https://github.com/rails/rails/compare/master...4-1-stable.diff https://github.com/rails/rails/compare/master...4-1-stable.patch ``` [*Read more about comparing commits across time.*](https://help.github.com/articles/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: ``` https://github.com/{user}/{repo}/compare/{foreign-user}:{branch}...{own-branch} ``` For example: ``` https://github.com/rails/rails/compare/byroot:master...master ```  ### Gists [Gists](https://gist.github.com/) 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](https://gist.github.com/tiimgreen/10545817.pibb)) in order to get the *HTML-only* version suitable for embedding in any other site. Gists can be treated as a repository so they can be cloned like any other: ```bash $ git clone https://gist.github.com/tiimgreen/10545817 ```  This means you also can modify and push updates to Gists: ```bash $ git commit $ git push Username for 'https://gist.github.com': Password for 'https://tiimgreen@gist.github.com': ``` However, Gists do not support directories. All files need to be added to the repository root. [*Read more about creating Gists.*](https://help.github.com/articles/creating-gists/) ### Git.io [Git.io](http://git.io) is a simple URL shortener for GitHub.  You can also use it via pure HTTP using Curl: ```bash $ curl -i http://git.io -F "url=https://github.com/..." HTTP/1.1 201 Created Location: http://git.io/abc123 $ curl -i http://git.io/abc123 HTTP/1.1 302 Found Location: https://github.com/... ``` [*Read more about Git.io.*](https://github.com/blog/985-git-io-github-url-shortener) ### 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 focus the search field for the current repository. Pressing ↓ to select the “All [GitHub](/@harrisonqian/awesome/wiki/development-environment/github)” option changes the field to search all of [GitHub](/@harrisonqian/awesome/wiki/development-environment/github). - Pressing `l` will edit labels on existing Issues. - Pressing `y` **when looking at a file** (e.g., `https://github.com/tiimgreen/github-cheat-sheet/blob/master/README.md`) 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 `?`:  [Read more about search syntax you can use.](https://help.github.com/articles/search-syntax/) ### Line Highlighting in Repositories Either adding, e.g., `#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: ``` https://github.com/rails/rails/blob/master/activemodel/lib/active_model.rb#L53-L60 ```  ### 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 repository's default branch. ```bash $ git commit -m "Fix screwup, fixes #12" ``` This closes the issue and references the closing commit.  [*Read more about closing Issues via commit messages.*](https://help.github.com/articles/closing-issues-via-commit-messages/) ### Cross-Link Issues If you want to link to another issue in the same repository, simply type hash `#` then the issue number, and it will be auto-linked. To link to an issue in another repository, `{user}/{repo}#ISSUE_NUMBER`, e.g., `tiimgreen/toc#12`.  ### Locking Conversations Pull Requests and Issues can now be locked by owners or collaborators of the repo.  This means that users who are not collaborators on the project will no longer be able to comment.  [*Read more about locking conversations.*](https://github.com/blog/1847-locking-conversations) ### CI Status on Pull Requests If set up correctly, every time you receive a Pull Request, [Travis CI](https://travis-ci.org/) 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](http://docs.travis-ci.com/user/getting-started/). [](https://github.com/octokit/octokit.rb/pull/452) [*Read more about the commit status API.*](https://github.com/blog/1227-commit-status-api) ### Filters Both issues and pull requests allow filtering in the user interface. For the Rails repo: https://github.com/rails/rails/issues, the following filter is built by selecting the label "activerecord": `is:issue label:activerecord` But, you can also find all issues that are NOT labeled activerecord: `is:issue -label:activerecord` Additionally, this also works for pull requests: `is:pr -label:activerecord` Github has tabs for displaying open or closed issues and pull requests but you can also see merged pull requests. Just put the following in the filter: `is:merged` [*Read more about searching issues.*](https://help.github.com/articles/searching-issues/) Finally, github now allows you to filter by the Status API's status. Pull requests with only successful statuses: `status:success` [*Read more about searching on the Status API.*](https://github.com/blog/2014-filter-pull-requests-by-status) ### Syntax Highlighting in Markdown Files For example, to syntax highlight Ruby code in your Markdown files write: ```ruby require 'tabbit' table = Tabbit.new('Name', 'Email') table.add_row('Tim Green', 'tiimgreen@gmail.com') puts table.to_s ``` This will produce: ```ruby require 'tabbit' table = Tabbit.new('Name', 'Email') table.add_row('Tim Green', 'tiimgreen@gmail.com') puts table.to_s ``` GitHub uses [Linguist](https://github.com/github/linguist) to perform language detection and syntax highlighting. You can find out which keywords are valid by perusing the [languages YAML file](https://github.com/github/linguist/blob/master/lib/linguist/languages.yml). [*Read more about GitHub Flavored Markdown.*](https://help.github.com/articles/github-flavored-markdown/) ### Emojis Emojis can be added to Pull Requests, Issues, commit messages, repository descriptions, etc. using `:name_of_emoji:`. The full list of supported Emojis on GitHub can be found at [emoji-cheat-sheet.com](http://www.emoji-cheat-sheet.com/) or [scotch-io/All-Github-Emoji-Icons](https://github.com/scotch-io/All-Github-Emoji-Icons). A handy emoji search engine can be found at [emoji.muan.co](http://emoji.muan.co/). The top 5 used Emojis on GitHub are: 1. `:shipit:` 2. `:sparkles:` 3. `:-1:` 4. `:+1:` 5. `:clap:` ### Images/GIFs Images and GIFs can be added to comments, READMEs etc.: ```  ``` Raw images from the repo can be used by calling them directly.: ```  ```  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: ```markdown [[ http://www.sheawong.com/wp-content/uploads/2013/08/keephatin.gif | height = 100px ]] ``` Which produces:  ### 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.  [*Read more about quick quoting.*](https://github.com/blog/1399-quick-quotes) ### Pasting Clipboard Image to Comments _(Works on Chrome browsers only)_ After taking a screenshot and adding it to the clipboard (mac: `cmd-ctrl-shift-4`), you can simply paste (`cmd-v / ctrl-v`) the image into the comment section and it will be auto-uploaded to github.  [*Read more about issue attachments.*](https://help.github.com/articles/issue-attachments/) ### Quick Licensing When creating a repository, GitHub gives you the option 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.*](https://help.github.com/articles/open-source-licensing/) ### Task Lists In Issues and Pull requests check boxes can be added with the following syntax (notice the space): ``` - [ ] Be [awesome](/@harrisonqian/awesome/wiki/miscellaneous/awesome) - [ ] Prepare dinner - [ ] Research recipe - [ ] Buy ingredients - [ ] Cook recipe - [ ] Sleep ```  When they are clicked, they will be updated in the pure Markdown: ``` - [x] Be [awesome](/@harrisonqian/awesome/wiki/miscellaneous/awesome) - [ ] Prepare dinner - [x] Research recipe - [x] Buy ingredients - [ ] Cook recipe - [ ] Sleep ``` [*Read more about task lists.*](https://help.github.com/articles/writing-on-github/#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](/@harrisonqian/awesome/wiki/miscellaneous/earth) - [x] Moon - [x] Mars - [ ] Deimos - [ ] Phobos ``` - [ ] Mercury - [x] Venus - [x] [Earth](/@harrisonqian/awesome/wiki/miscellaneous/earth) - [x] Moon - [x] Mars - [ ] Deimos - [ ] Phobos [*Read more about task lists in markdown documents.*](https://github.com/blog/1825-task-lists-in-all-markdown-documents) ### Relative Links Relative links are recommended in your Markdown files when linking to internal content. ```markdown [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.*](https://help.github.com/articles/relative-links-in-readmes/) ### 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](#emojis) and [@mentions](https://github.com/blog/821) in your Jekyll posts and pages to work just like you'd expect when interacting with a repository on GitHub.com. [*Read more about repository metadata and plugin support for GitHub Pages.*](https://github.com/blog/1797-repository-metadata-and-plugin-support-for-github-pages) ### Viewing YAML Metadata in your Documents Many blogging websites, like [Jekyll](http://jekyllrb.com/) with [GitHub Pages](https://pages.github.com), depend on some YAML-formatted metadata at the beginning of your post. GitHub will render this metadata as a horizontal table, for easier reading  [*Read more about viewing YAML metadata in your documents.*](https://github.com/blog/1647-viewing-yaml-metadata-in-your-documents) --- *truncated — [full list on GitHub](https://github.com/tiimgreen/github-cheat-sheet)*