このページの内容

Awesome GitHub Cheat Sheet

GitHub Cheat Sheetを扱う資料や関連プロジェクトをまとめたAwesomeリストです。

目次

GitHub

空白を無視

GitHub上で差分ページを表示している時、そのURLに?w=1を加えると、空白の変化によるできた差分は表示されなくなり、コード上の変化だけを参照することができる。

Diff without whitespace

GitHubの秘密についてもっと詳しく

タブ幅を調整

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.
タブ幅を調整についての日本語補足。

例えばGoのソースファイルを表示している時、?ts=4を追加する前はこのように表示されるが:

Before, tab space example

?ts=4を追加するとこのように表示される:

After, tab space example

作者別コミット履歴

特定のユーザーによるあるリポジトリへのコミット履歴のみを参照したい場合は、?author={user}をURLの末尾に付ける。

https://github.com/rails/rails/commits/master?author=dhh

DHH commit history

Read more about the differences between commits views.
作者別コミット履歴についての日本語補足。

リポジトリをクローン

リポジトリをクローンする時、URLの末尾の.gitは無くても構わない。

$ git clone https://github.com/tiimgreen/github-cheat-sheet

Gitのcloneコマンドについてもっと詳しく

ブランチ

全ブランチを別ブランチと比較

コミット一覧ボタンの隣からブランチ一覧ページに行くと:

https://github.com/{user}/{repo}/branches

メイン・ブランチにマージされていないブランチの一覧が表示される。

このページからボタンをクリックしてブランチ比較ページへ移動したりブランチを削除することができる。

Compare branches not merged into master in rails/rails repo - https://github.com/rails/rails/branches

ブランチ同士を比較

GitHubのブランチ比較は以下のようなURLで提供されている:

https://github.com/{user}/{repo}/compare/{range}

where {range} = master...4-1-stable
ブランチ同士を比較についての日本語補足。

例えば:

https://github.com/rails/rails/compare/master...4-1-stable

Rails branch compare example

{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
ブランチ同士を比較についての日本語補足。

Another compare example

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.
ブランチ同士を比較についての日本語補足。

フォークしたリポジトリ間でブランチを比較

GitHubでフォークされたリポジトリ同士でブランチを比較する場合、以下のようなURLを変更する:

https://github.com/{user}/{repo}/compare/{foreign-user}:{branch}...{own-branch}

例:

https://github.com/rails/rails/compare/byroot:master...master

Forked branch compare

Gist

Gistsは少量のコード群を管理する最適な手段だ。ちゃんとしたリポジトリをいちいち作成する必要はない。

Gist

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.
Gistについての日本語補足。

簡単なものとはいえ、Gitリポジトリとして機能するため、以下のようにすれば普通のGitリポジトリと同じようにクローンすることができる:

$ git clone https://gist.github.com/tiimgreen/10545817

Gists

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.
Gistについての日本語補足。 Read more about creating Gists.
Gistについての日本語補足。

Git.io

Git.ioはGitHubの提供するGitHub専用のシンプルな短縮URLサービスだ。

Git.io

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

Git.ioについてもっと詳しく

キーボードショートカット

リポジトリをブラウザーで開いている時は、ショートカットを利用して様々な機能ヘ簡単にアクセスできるようになっている。

  • 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” option changes the field to search all of 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. — キーボードショートカットに関する項目。

?を押すとそのページで使える全ショートカットが表示されるだろう。

Keyboard shortcuts

検索機能についてもっと詳しく

リポジトリ内の行を強調表示

コードのURLの末尾に#L52と付けるか行番号をクリックすると、その行が強調表示される。

これは範囲指定も可能だ(例: #L53-L60)。こういった範囲を選択するにはshiftを押しながら二つの行をクリックしても良い:

https://github.com/rails/rails/blob/master/activemodel/lib/active_model.rb#L53-L60

Line Highlighting

コミットメッセージでIssueを閉じる

あるコミットでissueを解決した場合、コミットメッセージでfix/fixes/fixedclose/closes/closedresolve/resolves/resolvedに続けてissue番号を指定すると、そのコミットがmasterブランチにpushされると同時に指定issueが閉じられるだろう。

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

こうするとissue#12が閉じられ、閉じたissueにはそのコミットへの参照が自動的に追加される。

Closing Repo

Read more about closing Issues via commit messages.
コミットメッセージでIssueを閉じるについての日本語補足。

Issueを相互リンク

同じリポジトリの違うissueへリンクを張り参照させたい場合、#に続けてissue番号を指定する。そうすると自動的にリンクが作成されるだろう。

別のリポジトリのissueの場合は{user}/{repo}#ISSUE_NUMBERとすれば良い(例: tiimgreen/toc#12)。

Cross-Link Issues

会話をロック

リポジトリのオーナーや共同開発者ならば、pull requestやissueへのコメントをロックできるようになった。

Lock conversation

つまりそのプロジェクトの共同開発者ではないユーザーはコメントをすることができないということだ。

Comments locked

コメントのロックについてもっと詳しく

プルリクエストのCI状態

適切に設定を行えばpull requestを受け取るたびに、通常のコミットと同じようにTravis CIがそのpull requestをビルドするだろう。どう設定するかはTravis CI: Getting startedを読むと良い。

Travis CI status

コミット・ステータスAPIについてもっと詳しく

フィルター

issueとpull requestの検索インターフェイスでは、絞り込みをかけることが可能だ。

For the Rails repo: https://github.com/rails/rails/issues, the following filter is built by selecting the label “activerecord”:
フィルターについての日本語補足。

is:issue label:activerecord

逆に”activerecord”というラベルがついていないissueのみを表示することもできる:

is:issue -label:activerecord

そして、この絞り込み検索はpull requestに対しても行うことができる:

is:pr -label:activerecord

GitHubでは開かれているissueやpull requestのみを表示するタブ、または既に閉じられたそれらのみを表示するタブが用意されているが、絞り込み検索によってマージ済みのpull requestのみを表示することもできる。以下のようなフィルターを使えば良いだろう:

is:merged

Read more about searching issues.
フィルターについての日本語補足。

そしてGitHubはStatus APIの結果を使ってフィルターすることもできるようになった。

Status APIでsuccessが設定されたpull requestのみ:

status:success

Status APIを使った絞り込み検索についてもっと詳しく

Markdownファイルの構文強調

例えばMarkdownファイルでRubyのコードを構文強調したいならば以下のようにする:

```ruby
require 'tabbit'
table = Tabbit.new('Name', 'Email')
table.add_row('Tim Green', 'tiimgreen@gmail.com')
puts table.to_s
```

こうすると以下のように表示されることになる:

require 'tabbit'
table = Tabbit.new('Name', 'Email')
table.add_row('Tim Green', 'tiimgreen@gmail.com')
puts table.to_s

GitHubではLinguistを使って言語を判別し構文強調を行っている。構文強調がサポートされている言語の一覧は言語定義YAMLファイルを参照すればわかるだろう。

Read more about GitHub Flavored Markdown.
Markdownファイルの構文強調についての日本語補足。

絵文字

Emojiはpull requestやissue、コミット・メッセージ、リポジトリーの概要などで:name_of_emoji:と書くと利用できる:

GitHubでサポートされているEmojiの完全なリストはEmoji cheat sheet for Campfire and GitHubAll-Github-Emoji-Iconsで確認できる。 素敵なemojiの検索はemoji.muan.co

GitHubで使われているEmojiのトップ5は以下の通りだ:

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

画像・GIF

画像やアニメーションGIFはコミットのコメントやREADMEなどで利用できる:

![Alt Text](http://www.sheawong.com/wp-content/uploads/2013/08/keephatin.gif)

リポジトリにある画像も直接参照することが出来る:

![Alt Text](https://github.com/{user}/{repo}/raw/master/path/to/image.gif)

Peter don't care

あらゆる画像はGitHubでキャッシュされるので、画像のホスティング先が落ちていたとしても変わらず表示されるだろう。

GitHub Wikiへ画像を埋め込む

GitHub Wikiで画像を追加する方法がいくつかある。通常のMarkdown記法(前節を参照)はもちろん使える。しかしそれだけではなく、画像の幅と高さを指定する記法も使うことができる:

[[ http://www.sheawong.com/wp-content/uploads/2013/08/keephatin.gif | height = 100px ]]

こうすると以下のようになる:

Just a screenshot

素早く引用

issueのスレッドで他の人のコメントを引用してコメントしたい場合、引用したい文章を選択した状態でrを押すと、ブロック引用の記法を使ってテキストエリアにコピーされる。

Quick Quote

素早く引用する方法についてもっと詳しく

クリップボード画像をコメントへ貼り付ける

(Chrome系のブラウザーのみで動作)

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.
クリップボード画像をコメントへ貼り付けるについての日本語補足。

Pasting Clipboard Image to Comments

Read more about issue attachments.
クリップボード画像をコメントへ貼り付けるについての日本語補足。

素早くライセンスを設定

GitHub上でリポジトリを作成する時、あらかじめ設定されているライセンスを追加することもできる:

Licese

既に存在するリポジトリであってもウェブ上のインターフェイスからファイルを作成することで追加できる。LICENSEというファイル名にした場合、ライセンスを選択するオプションが表示されるのだ:

License

.gitignoreも同じように作成時に追加することも、後で追加することもできる。

Read more about open source licensing.
素早くライセンスを設定についての日本語補足。

タスクリスト

issueやpull requestでは以下のように(空白に注意)書くとチェックボックスを作成することができる:

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

Task List

これらチェックボックスにチェックが入れられると、同時にMarkdownソースも更新される:

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

Read more about task lists.
タスクリストについての日本語補足。

Markdown文書内のタスクリスト

通常のMarkdownファイルでも読み取り専用のチェックリストを以下のような記法で追加することができる:

- [ ] Mercury
- [x] Venus
- [x] Earth
  - [x] Moon
- [x] Mars
  - [ ] Deimos
  - [ ] Phobos
  • Mercury — Markdown文書内のタスクリストに関する項目。
  • Venus — Markdown文書内のタスクリストに関する項目。
  • Earth — Markdown文書内のタスクリストに関する項目。
    • Moon — Markdown文書内のタスクリストに関する項目。
  • Mars — Markdown文書内のタスクリストに関する項目。
    • Deimos — Markdown文書内のタスクリストに関する項目。
    • Phobos — Markdown文書内のタスクリストに関する項目。

Markdownファイルでのタスクリストについてもっと詳しく

相対リンク

Markdownファイルでリポジトリ内のコンテンツへ張る場合、相対リンクを利用することが推奨されている。

[Link to a header](#awesome-section)
[Link to a file](https://github.com/tiimgreen/github-cheat-sheet/blob/746af1b42356973f66627319bbaf4ac5157c5308/docs/readme)

絶対リンクはURLの変更(例: リポジトリのリネーム、ユーザー名の変更、プロジェクトのフォーク)により更新される。相対リンクを利用すれば、そのままうまく機能するはずだ。

Read more about relative links.
相対リンクについての日本語補足。

GitHub Pagesのメタデータとプラグイン対応

Jekyllのページや投稿ではリポジトリの情報がsite.githubという名前空間に格納されており、例えば{{ 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 GitHub.com.
GitHub Pagesのメタデータとプラグイン対応についての日本語補足。

GitHub Pageでのメタデータとプラグインのサポートについてもっと詳しく

文書内のYAMLメタデータを表示

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メタデータを表示についての日本語補足。

YAML metadata

文書内のYAMLメタデータの表示についてもっと詳しく

表形式データを表示

GitHubでは.csv(カンマ区切り)と.tsv(タブ区切り)の形式で書かれた表を整形して表示する機能をサポートしている。

Tabular data

表形式のデータ表示についてもっと詳しく

PDFを表示

GitHubではPDFの表示をサポートしている:

PDF

PDF表示についてもっと詳しく

プルリクエストを取り消す

pull requestをマージした後、意味がなかったことがわかったり、そのpull requestをマージしたのは間違いだったことがわかることもあるだろう。

その取り消しは、pull requestのページに表示されているマージ・コミットの右端にあるRevertボタンをクリックすることにより、そのpull requestで行われた変更を取り消すpull requestを作成することによって行うことができる。

Revert button

pull requestの取り消しについてもっと詳しく

差分

レンダリング済み文書の差分

コミットやpull requestにGitHubでレンダリングされて表示されるもの(例: Markdown)が含まれる場合、そのソースレンダリング済みの両方の差分を見ることができる。

Source / Rendered view

レンダリングされた状態での差分を表示したい場合は「Rendered」ボタンをクリックする。レンダリング済みの差分表示では文章の追加や削除、編集がよりわかりやすい:

Rendered Prose Diffs

レンダリング済みの差分表示についてもっと詳しく

地図の差分

コミットやpull requestにジオデータの変更が含まれている場合はいつも、GitHubではそのジオデータの変化を可視化してくれるだろう。

Diffable Maps

マップ差分の可視化についてもっと詳しく

差分の前後を展開

差分表示の行番号付近にある展開ボタンを使うと、その前後の行をクリックして表示させることができる。展開ボタンを押し続けることによってファイル全体を表示することもできるし、またこの機能はあらゆるGitHubの差分表示ビューに用意されている。

Expanding Context in Diffs

差分表示の前後を表示についてもっと詳しく

プルリクエストのdiff・patch

pull requestによる差分はそのURLの末尾に.diffまたは.patchを追加すると、それぞれの形式で取得することができる。例えば:

https://github.com/tiimgreen/github-cheat-sheet/pull/15
https://github.com/tiimgreen/github-cheat-sheet/pull/15.diff
https://github.com/tiimgreen/github-cheat-sheet/pull/15.patch

拡張子.diffを追加した場合、このようなプレーンテキストで表示されるだろう:

diff --git a/README.md b/README.md
index 88fcf69..8614873 100644
--- a/README.md
+++ b/README.md
@@ -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

(...)

画像の表示と差分

GitHubは、PNGやJPG、GIF、PSDといった多くの一般的な画像形式の表示をサポートしている。それに加え、様々な方法でこれら画像形式のバージョンごとの差分を比較することもできる。

Diffable PSD

Read more about rendering and diffing images.
画像の表示と差分についての日本語補足。

Hub

HubはGitのラッパーとして機能するコマンドライン・ツールで、これを利用するとGitHubをコマンドラインからとても簡単に扱えるようになる。

例えば以下のようにしてリポジトリのクローンが行える:

$ hub clone tiimgreen/toc

Check out some more cool commands Hub has to offer.
Hubについての日本語補足。

貢献ガイドライン

GitHub supports adding 3 different files which help users contribute to your project.
貢献ガイドラインについての日本語補足。 These files can either be placed in the root of your repository or a .github directory under the root.
貢献ガイドラインについての日本語補足。

CONTRIBUTINGファイル

Adding a CONTRIBUTING or CONTRIBUTING.md file to either the root of your repository or a .github directory will add a link to your file when a contributor creates an Issue or opens a Pull Request.
CONTRIBUTINGファイルについての日本語補足。

Contributing Guidelines

Read more about contributing guidelines.
CONTRIBUTINGファイルについての日本語補足。

ISSUE_TEMPLATEファイル

You can define a template for all new issues opened in your project. The content of this file will pre-populate the new issue box when users create new issues. Add an ISSUE_TEMPLATE or ISSUE_TEMPLATE.md file to either the root of your repository or a .github directory.
ISSUE_TEMPLATEファイルについての日本語補足。

Read more about issue templates.
ISSUE_TEMPLATEファイルについての日本語補足。

Issue template file generator
ISSUE_TEMPLATEファイルについての日本語補足。

GitHub Issue template

PULL_REQUEST_TEMPLATEファイル

You can define a template for all new pull requests opened in your project. The content of this file will pre-populate the text area when users create pull requests. Add a PULL_REQUEST_TEMPLATE or PULL_REQUEST_TEMPLATE.md file to either the root of your repository or a .github directory.
PULL_REQUEST_TEMPLATEファイルについての日本語補足。

Read more about pull request templates.
PULL_REQUEST_TEMPLATEファイルについての日本語補足。

Pull request template file generator
PULL_REQUEST_TEMPLATEファイルについての日本語補足。

Octicons

GitHubで使われているアイコン(Octicons)はオープンソース化された。

Octicons

GitHubのOcticonsについてもっと詳しく

GitHub Student Developer Pack

If you are a student you will be eligible for the GitHub Student Developer Pack. This gives you free credit, free trials and early access to software that will help you when developing.
GitHub Student Developer Packについての日本語補足。

GitHub Student Developer Pack

Read more about GitHub’s Student Developer Pack
GitHub Student Developer Packについての日本語補足。

GitHub資料

| Title | Link |
GitHub資料についての日本語補足。 | ----- | ---- |
GitHub資料についての日本語補足。 | GitHub Explore | https://github.com/explore |
GitHub資料についての日本語補足。 | GitHub Blog | https://github.com/blog |
GitHub資料についての日本語補足。 | GitHub Help | https://help.github.com/ |
GitHub資料についての日本語補足。 | GitHub Training | https://training.github.com/ |
GitHub資料についての日本語補足。 | GitHub Developer | https://developer.github.com/ |
GitHub資料についての日本語補足。 | Github Education (Free Micro Account and other stuff for students) | https://education.github.com/ |
GitHub資料についての日本語補足。 | GitHub Best Practices | Best Practices List |
GitHub資料についての日本語補足。

GitHub講演

TitleLink
How GitHub Uses GitHub to Build GitHubhttps://www.youtube.com/watch?v=qyz3jkOBbQY
Introduction to Git with Scott Chacon of GitHubhttps://www.youtube.com/watch?v=ZDR433b0HJY
How GitHub No Longer Workshttps://www.youtube.com/watch?v=gXD1ITW7iZI
Git and GitHub Secretshttps://www.youtube.com/watch?v=Foz9yvMkvlA
More Git and GitHub Secretshttps://www.youtube.com/watch?v=p50xsL-iVgU

SSH鍵

You can get a list of public ssh keys in plain text format by visiting:
SSH鍵についての日本語補足。

https://github.com/{user}.keys

e.g. https://github.com/tiimgreen.keys
SSH鍵についての日本語補足。

Read more about accessing public ssh keys.
SSH鍵についての日本語補足。

プロフィール画像

You can get a user’s profile image by visiting:
プロフィール画像についての日本語補足。

https://github.com/{user}.png

e.g. https://github.com/tiimgreen.png
プロフィール画像についての日本語補足。

リポジトリテンプレート

You can enable templating on your repository which allows anyone to copy the directory structure and files, allowing them to instantly use the files (e.g. for a tutorial or if writing boilerplate code). This can be enabled in the settings of your repository.
リポジトリテンプレートについての日本語補足。

Convert

Changing to a template repository will give a new URL endpoint which can be shared and instantly allows users to use your repository as a template. Alternatively, they can go to your repository and click the ‘Use as template’ button.
リポジトリテンプレートについての日本語補足。

Template

Read more about using repositories as templates
リポジトリテンプレートについての日本語補足。

Git

削除済みファイルをワークツリーからすべて削除

例えば/bin/rmを使って大量のファイルを削除した場合、以下のコマンドを使えばワーキング・ツリー、そしてインデックスからも削除することができ、ファイルごとにそれぞれGitコマンドを実行する必要がなくなる:

$ git rm $(git ls-files -d)

例えば以下のように実行される:

$ git status
On branch master
Changes not staged for commit:
	deleted:    a
	deleted:    c

$ git rm $(git ls-files -d)
rm 'a'
rm 'c'

$ git status
On branch master
Changes to be committed:
	deleted:    a
	deleted:    c

直前のブランチ

Gitで直前のブランチへ移動するには:

$ git checkout -
# Switched to branch 'master'

$ git checkout -
# Switched to branch 'next'

$ git checkout -
# Switched to branch 'master'

Gitのブランチ操作についてもっと詳しく

空白を除去

Git Stripspace:
空白を除去についての日本語補足。

  • 行末の空白文字の削除
  • 空白行の取りまとめ
  • ファイル末尾への改行の追加

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

$ git stripspace < README.md

Read more about the Git stripspace command.
空白を除去についての日本語補足。

プルリクエストをチェックアウト

pull requestはGitHubのリポジトリでは特別なブランチであり、様々な方法でローカルに取り込むことができる:

Retrieve a specific Pull Request and store it temporarily in FETCH_HEAD for quickly diff-ing or merge-ing:
プルリクエストをチェックアウトについての日本語補足。

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

参照仕様を使うとすべてのpull requestをローカル・ブランチとして取り込むことができる:

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

リポジトリの.git/configに以下の行を追加すれば自動的にpull requestを落とすようにもできるだろう:

[remote "origin"]
    fetch = +refs/heads/*:refs/remotes/origin/*
    url = git@github.com:tiimgreen/github-cheat-sheet.git
[remote "origin"]
    fetch = +refs/heads/*:refs/remotes/origin/*
    url = git@github.com: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

もしくは様々なリポジトリで作業をするのなら、代わりにグローバルのGit設定で行うことにより、pull requestの取得をグローバルに設定すると良いだろう。

git config --global --add remote.origin.fetch "+refs/pull/*/head:refs/remotes/origin/pr/*"

こうすると以下の様な短いコマンドを利用することが可能になる:

git fetch origin
git checkout pr/42

Read more about checking out pull requests locally.
プルリクエストをチェックアウトについての日本語補足。

空コミット

--allow-emptyオプションを付けると、コードの変化がなくてもコミットを作成することができる:

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

この機能の使い方(便利なもの)としては以下のようなものが挙げられる:

  • 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 repository: git commit -m "Initial commit" --allow-empty. — 空コミットに関する項目。

Git statusを装飾

普通に実行すると:

$ git status

このように表示されるが:

git status

-sbを追加することによって:

$ git status -sb

このように表示することもできる:

git status -sb

Gitのstatusコマンドについてもっと詳しく

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

この設定はPaleszが考えたものだ。

This can be aliased using the instructions found here.
Git logを装飾についての日本語補足。

Gitのlogコマンドについてもっと詳しく

Gitログを検索

指定した文字列を今までのコミット・メッセージから検索して、もっとも新しいものを表示することができる。

$ git show :/query

queryを検索したい文字列(大文字と小文字を区別する)で置き換えると、最新のコミットがそのコミットにおける差分と同時に表示される。

$ git show :/typo

git show :/query

注: 終了するにはqを押す。

Git grep

Git Grepは指定したパターンに一致する行の一覧を返してくれる。

Running:

$ git grep aliases

will show all the files containing the string aliases.

git grep aliases

Press q to quit.
Git grepについての日本語補足。

You can also use multiple flags for more advanced search. For example:
Git grepについての日本語補足。

  • -e The next parameter is the pattern (e.g., regex) — Git grepに関する項目。
  • --and, --or and --not Combine multiple patterns. — Git grepに関する項目。

Use it like this:

 $ git grep -e pattern --and -e anotherpattern

Read more about the Git grep command.
Git grepについての日本語補足。

マージ済みブランチ

以下のように実行すると:

$ git branch --merged

現在のブランチに既にマージされたブランチの一覧が表示される。

逆に:

$ git branch --no-merged

こうするとまだマージされていないブランチが表示されるだろう。

Gitのbranchコマンドについてもっと詳しく

fixupとautosquash

If there is something wrong with a previous commit (can be one or more from HEAD), for example abcde, run the following command after you’ve amended the problem:

$ git commit --fixup=abcde
$ git rebase abcde^ --autosquash -i

Read more about the Git commit command. Read more about the Git rebase command.

ローカルリポジトリ閲覧用ウェブサーバー

Gitのinstawebコマンドを利用すると、自分の作業リポジトリをgitwebで参照することができる。このコマンドはgitwebとウェブサーバーをセットアップしてローカル・リポジトリをブラウザーで開けるようにする簡単なスクリプトだ。

$ git instaweb

以下のようなページが開かれる:

Git instaweb

Gitのinstawebコマンドについてもっと詳しく

Git設定

.gitconfigとはあらゆる設定が書き込まれるファイルだ。

エイリアス

エイリアスはGitの呼び出し方を自分で好きなように定義できるヘルパー機能だ。例えばgit agit add --allを実行するようにすることができる。

エイリアスを追加するには~/.gitconfigを開き、以下のような形式で記述していく:

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

またはコマンドラインからも設定できる:

$ git config --global alias.new_alias git_function

例:

$ git config --global alias.cm commit

注: エイリアスが複数のコマンドからなる場合はクオートで括る必要がある:

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

おすすめの設定を挙げておこう:

エイリアスコマンド設定方法
git cmgit commitgit config --global alias.cm commit
git cogit checkoutgit config --global alias.co checkout
git acgit add . -A git commitgit config --global alias.ac '!git add -A && git commit'
git stgit status -sbgit config --global alias.st 'status -sb'
git tagsgit tag -lgit config --global alias.tags 'tag -l'
git branchesgit branch -agit config --global alias.branches 'branch -a'
git cleanupgit branch --merged | grep -v '*' | xargs git branch -dgit config --global alias.cleanup "!git branch --merged | grep -v '*' | xargs git branch -d"
git remotesgit remote -vgit config --global alias.remotes 'remote -v'
git lggit 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: https://github.com/mathiasbynens/dotfiles/blob/master/.gitconfig
エイリアスについての日本語補足。

自動修正

Gitはスペルを誤ったコマンドに候補を提示します。自動修正を有効にすると、修正したコマンドを自動実行できます。設定値は実行までの0.1秒単位の待ち時間で、既定の0では修正せず、負数では待たずに実行します。

たとえばgit comitと入力すると次のように表示されます。

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

# Did you mean this?
#   commit

自動修正を1.5秒の待ち時間で有効にします。

$ git config --global help.autocorrect 15

これでgit comitは次のようにgit commitへ自動修正されます。

$ 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 1.5 seconds automatically...

再実行前の待ち時間は、利用者が中止できるようにするためのものです。

Gitの出力をカラフルにするには以下のような設定を加えると良い:

$ git config --global color.ui 1

Gitのconfigコマンドについてもっと詳しく

Git資料

| Title | Link |
Git資料についての日本語補足。 | ----- | ---- |
Git資料についての日本語補足。 | Official Git Site | http://git-scm.com/ |
Git資料についての日本語補足。 | Official Git Video Tutorials | http://git-scm.com/videos |
Git資料についての日本語補足。 | Code School Try Git | http://try.github.com/ |
Git資料についての日本語補足。 | Introductory Reference & Tutorial for Git | http://gitref.org/ |
Git資料についての日本語補足。 | Official Git Tutorial | http://git-scm.com/docs/gittutorial |
Git資料についての日本語補足。 | Everyday Git | http://git-scm.com/docs/everyday |
Git資料についての日本語補足。 | Git Immersion | http://gitimmersion.com/ |
Git資料についての日本語補足。 | Git God | https://github.com/gorosgobe/git-god |
Git資料についての日本語補足。 | Git for Computer Scientists | http://eagain.net/articles/git-for-computer-scientists/ |
Git資料についての日本語補足。 | Git Magic | http://www-cs-students.stanford.edu/~blynn/gitmagic/ |
Git資料についての日本語補足。 | Git Visualization Playground | http://onlywei.github.io/explain-git-with-d3/#freeplay |
Git資料についての日本語補足。 | Learn Git Branching | http://pcottle.github.io/learnGitBranching/ |
Git資料についての日本語補足。 | A collection of useful .gitignore templates | https://github.com/github/gitignore |
Git資料についての日本語補足。 | Unixorn’s git-extra-commands collection of git scripts | https://github.com/unixorn/git-extra-commands |
Git資料についての日本語補足。

Git書籍

| Title | Link |
Git書籍についての日本語補足。 | ----- | ---- |
Git書籍についての日本語補足。 | Pragmatic Version Control Using Git | https://pragprog.com/titles/tsgit/pragmatic-version-control-using-git |
Git書籍についての日本語補足。 | Pro Git | http://git-scm.com/book |
Git書籍についての日本語補足。 | Git Internals PluralSight | https://github.com/pluralsight/git-internals-pdf |
Git書籍についての日本語補足。 | Git in the Trenches | http://cbx33.github.io/gitt/ |
Git書籍についての日本語補足。 | Version Control with Git | http://www.amazon.com/Version-Control-Git-collaborative-development/dp/1449316387 |
Git書籍についての日本語補足。 | Pragmatic Guide to Git | https://pragprog.com/titles/pg_git/pragmatic-guide-to-git |
Git書籍についての日本語補足。 | Git: Version Control for Everyone | https://www.packtpub.com/application-development/git-version-control-everyone |
Git書籍についての日本語補足。

Git動画

| Title | Link |
Git動画についての日本語補足。 | ----- | ---- |
Git動画についての日本語補足。 | Linus Torvalds on Git | https://www.youtube.com/watch?v=4XpnKHJAok8 |
Git動画についての日本語補足。 | Introduction to Git with Scott Chacon | https://www.youtube.com/watch?v=ZDR433b0HJY |
Git動画についての日本語補足。 | Git From the Bits Up | https://www.youtube.com/watch?v=MYP56QJpDr4 |
Git動画についての日本語補足。 | Graphs, Hashes, and Compression, Oh My! | https://www.youtube.com/watch?v=ig5E8CcdM9g |
Git動画についての日本語補足。 | GitHub Training & Guides | https://www.youtube.com/watch?list=PLg7s6cbtAD15G8lNyoaYDuKZSKyJrgwB-&v=FyfwLX4HAxM |
Git動画についての日本語補足。

Git記事

| Title | Link |
Git記事についての日本語補足。 | ----- | ---- |
Git記事についての日本語補足。 | GitHub Flow | http://scottchacon.com/2011/08/31/github-flow.html |
Git記事についての日本語補足。 | Migrating to Git Large File Storate (Git LFS) | http://vooban.com/en/tips-articles-geek-stuff/migrating-to-git-lfs-for-developing-deep-learning-applications-with-large-files/ |
Git記事についての日本語補足。