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).
Shortlink: http://git.io/sheet
Read this in other languages: English, 한국어, 日本語, 简体中文, 正體中文.
GitHub Cheat Sheet is sponsored by Snapshot: create interactive professional-quality product photos using AI
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.
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 can automate this.
Here is a Go source file before adding ?ts=4:

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

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.
When cloning a repository the .git can be left off the end.
$ git clone https://github.com/tiimgreen/github-cheat-sheet
Read more about the Git clone command.
If you go to the repo's 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.

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.
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 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 repository so they can be cloned like any other:
$ git clone https://gist.github.com/tiimgreen/10545817

This means you also can modify and push updates to Gists:
$ 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.
Git.io is a simple URL shortener for GitHub.

You can also use it via pure HTTP using Curl:
$ 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/...
When on a repository page, keyboard shortcuts allow you to navigate easily.
t will bring up a file explorer.w will bring up the branch selector.s will focus the search field for the current repository. Pressing ↓ to select the “All GitHub” option changes the field to search all of GitHub.l will edit labels on existing Issues.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.
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

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.
$ git commit -m "Fix screwup, fixes #12"
This closes the issue and references the closing commit.

Read more about closing Issues via commit messages.
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.
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.
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.
Read more about the commit status API.
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.
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.
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:
require 'tabbit' table = Tabbit.new('Name', 'Email') table.add_row('Tim Green', 'tiimgreen@gmail.com') 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


稳定高效的流量提升解决方案,助力品牌曝光
稳定高效的流量提升解决方案,助力品牌曝光


最新版Sora2模型免费使用,一键生成无水印视频
最新版Sora2模型免费使用,一键生成无水印视频


实时语音翻译/同声传译工具
Transly是一个多场景的AI大语言模型驱动的同声传译、专业翻译助手,它拥有超精准的音频识别翻译能力,几乎零延迟的使用体验和支持多国语言可以让你带它走遍全球,无论你是留学生、商务人士、韩剧美剧爱好者, 还是出国游玩、多国会议、跨国追星等等,都可以满足你所有需要同传的场景需求,线上线下通用,扫除语言障碍,让全世界的语言交流不再有国界。


选题、配图、成文,一站式创作,让内容运营更高效
讯飞绘文,一个AI集成平台,支持写作、选题、配图、排版和发布。高效生成适用于各类媒体的定制内容,加速品牌传播,提升内容营销效果。


AI辅助编程,代码自动修复
Trae是一种自适应的集成开发环境(IDE),通过自动化和多元协作改变开发流程。利用Trae,团队能够更快速、精确地编写和部署代码,从而提高编程效率和项目交付速度。Trae具备上下文感知和代码自动完成功能,是提升开发效率的理想工具。


最强AI数据分析助手
小浣熊家族Raccoon,您的AI智能助手,致力于通过先进的人工智能技术,为用户提供高效、便捷的智能服务。无论是日常咨询还是专业问题解答,小浣熊都能 以快速、准确的响应满足您的需求,让您的生活更加智能便捷。


像人一样思考的AI智能体
imini 是一款超级AI智能体,能根据人类指令,自主思考、自主完成、并且交付结果的AI智能体。


AI数字人视频创作平台
Keevx 一款开箱即用的AI数字人视频创作平台,广泛适用于电商广告、企业培训与社媒宣传,让全球企业与个人创作者无需拍摄剪辑,就能快速生成多语言、高质量的专业视频。


一站式AI创作平台
提供 AI 驱动的图片、视频生成及数字 人等功能,助力创意创作


AI办公助手,复杂任务高效处理
AI办公助手,复杂任务高效处理。办公效率低?扣子空间AI助手支持播客生成、PPT制作、网页开发及报告写作,覆盖科研、商业、舆情等领域的专家Agent 7x24小时响应,生活工作无缝切换,提升50%效率!
最新AI工具、AI资讯
独家AI资源、AI项目落地

微信扫一扫关注公众号