GitHub:技巧集合

708 查看

列出所有文件

仓库 URL + find/分支名称,例如:https://github.com/onestark/learn-css/find/master

Raw 文件

在浏览器中以 text/plain 查看原始文件。

例如,GitHub 文件原链接:

https://github.com/onestark/alfred-workflows/blob/master/README.md

可通过以下几种 URL 查看 raw 文件:

https://raw.githubusercontent.com/onestark/alfred-workflows/master/README.md
https://github.com/onestark/alfred-workflows/raw/master/README.md
https://github.com/onestark/alfred-workflows/blob/master/README.md?raw=true

文件下载

不支持 Raw 查看的文件,在浏览器中输入或点击上述查看 raw 文件的 URL 时,会对文件进行下载。因此可以通过这个特性,在 GitHub 上直接提供文件的下载功能。

支持 Raw 查看的文件,可在浏览器打开 raw 页面,直接 另存为... 保存即可

展示 Demo

GitHub 仓库开通 GitHub Pages 后,其中的 HTML 文件就可以被浏览器正确渲染了,因此这个功能不仅可以作为项目的展示页,也可以展示各种 HTML demo 文件。

RawGit

When you request certain types of files (like JavaScript, CSS, or HTML) from raw.githubusercontent.com or gist.githubusercontent.com, GitHub serves them with a Content-Type header set to text/plain. As a result, most modern browsers won't actually interpret these files as JavaScript, CSS, or HTML and will instead just display them as text.

RawGit 作为一个缓存代理,提供的功能是缓存 GitHub 中 raw 文件并添加上正确的 Content-Type header,从而使文件能被浏览器正确渲染。

RawGit 对未开通 GitHub Pages 的项目中的任意 HTML/CSS/JS 文件以及 Gist 代码的渲染展示提供了方便。

使用方法:https://rawgit.com/https://raw.githack.com/

添加 LICENSE

  • 创建项目时,有添加 LICENSE 选项;

  • 创建项目后,添加新文件,输入文件名 LICENSE 时右侧会出现 LICENSE 模板选项。