github/gitignore · Ruby.gitignore
Ruby .gitignore テンプレート解説
Ruby.gitignore が gem パッケージ、Bundler のインストールフォルダー、テスト結果、ドキュメント生成物を無視する理由と、Gemfile.lock・.ruby-version のコミット基準を説明します。
Ruby.gitignore は gem を作ったり Ruby のスクリプト・アプリケーションを開発したりするプロジェクト向けである。ほとんどのルールが / で始まりリポジトリルートに固定されているため、同名のサブフォルダーを誤って無視することが少ない。
Rails アプリケーションなら、このテンプレートよりも Rails テンプレートの方が多くのケースを扱う。両方を選択すると、重なるルールは重複除去で整理される。
ルール別の解説
| パターン | 何を、なぜ無視するか |
|---|---|
*.gem/pkg/ | gem パッケージgem build と rake build が作るパッケージファイルである。RubyGems に公開する成果物である。 |
/.bundle//vendor/bundle/lib/bundler/man/ | Bundler.bundle/ にはローカルの Bundler 設定が、vendor/bundle には bundle install --path でインストールした gem が入る。別のコンピューターで再インストールできる。 |
/coverage//spec/reports//spec/examples.txt/test/tmp//test/version_tmp/ | テスト結果SimpleCov の結果、RSpec のレポート、RSpec が失敗したサンプルを記録する examples.txt などの実行結果である。 |
/.yardoc//_yardoc//doc//rdoc/ | ドキュメント生成物YARD・RDoc が作った API ドキュメントとキャッシュである。ソースのコメントから作り直せる。 |
/tmp/.byebug_history.repl_history*.rbc/.config/InstalledFiles | 一時・デバッガーファイル一時フォルダー、byebug・REPL の履歴、Rubinius のバイトコード、setup.rb のインストール記録である。 |
.rvmrc | バージョンマネージャーの設定RVM の古いプロジェクト設定ファイルで、シェルコードを実行できるため共有を避ける。最近は主に .ruby-version を使う。 |
実務での注意点
- テンプレートのコメントのとおり、アプリケーションは
Gemfile.lockと.ruby-versionをコミットし、さまざまな環境で使われるライブラリ(gem)は無視する場合がある。 /doc/はルートのdocフォルダー全体を無視する。手書きのドキュメントをdoc/に置くなら、この行を削除して/doc/api/のように生成パスだけを指定する。.envルールはこのテンプレートにコメントとしてしかないため、環境変数ファイルを使うなら直接追加する。
元のテンプレート
Ruby.gitignore
*.gem*.rbc/.config/coverage//InstalledFiles/pkg//spec/reports//spec/examples.txt/test/tmp//test/version_tmp//tmp/# Used by dotenv library to load environment variables.# .env# Ignore Byebug command history file..byebug_history## Specific to RubyMotion:.dat*.repl_historybuild/*.bridgesupportbuild-iPhoneOS/build-iPhoneSimulator/## Specific to RubyMotion (use of CocoaPods):## We recommend against adding the Pods directory to your .gitignore. However# you should judge for yourself, the pros and cons are mentioned at:# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control## vendor/Pods/## Documentation cache and generated files:/.yardoc//_yardoc//doc//rdoc/## Environment normalization:/.bundle//vendor/bundle/lib/bundler/man/# for a library or gem, you might want to ignore these files since the code is# intended to run in multiple environments; otherwise, check them in:# Gemfile.lock# .ruby-version# .ruby-gemset# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:.rvmrc# Used by RuboCop. Remote config files pulled in from inherit_from directive.# .rubocop-https?--*
テンプレートの出典: github/gitignore/Ruby.gitignore @356fd7b (2026-09-11) · CC0-1.0