gitignore を記述する時に便利なテンプレート集の紹介です。
プロジェクトで ソースコードのバージョン管理をする時に Git を使う事が多いと思います。
Git には、レポジトリに含めたくない ファイルや ディレクトリを定義する為の除外機能が備わっており、その場合は ' .gitignore
' ファイルに記述します。
# 一般的な gitignoreの記述例
node_modules/ # ディレクトリ 'node_modules'を除外
*.log # 拡張子が log のファイルを除外
exclude.text # ファイル 'exclude.text'を除外
gitignore の記述自体は決して難しいものではありませんが、プロジェクトの種類や、開発環境、言語、OSやテキストエディタ 固有の隠しファイル、フレームワークなど 除外できるものを考えればキリがありません。
そんな gitignore内 に含めたほうがよい 記述が集められたテンプレート集が GitHub公式レポジトリの gitignore です。

Ruby On Rails
Ruby On Rails は Rubyで開発されている Webフレームワークで、MVCフレームワーク単体で見れば最も知名度が高く、幅広いプロジェクトで使用されています。
隠しファイルや Unitテストを実行した時に作成される一時フォルダ、アセットファイル用の ' node_modules
' フォルダまで記述されています。
*.rbc
capybara-*.html
.rspec
/log
/tmp
/db/*.sqlite3
/db/*.sqlite3-journal
/public/system
/coverage/
/spec/tmp
*.orig
rerun.txt
pickle-email-*.html
# TODO Comment out this rule if you are OK with secrets being uploaded to the repo
config/initializers/secret_token.rb
config/master.key
# Only include if you have production secrets in this file, which is no longer a Rails default
# config/secrets.yml
# dotenv
# TODO Comment out this rule if environment variables can be committed
.env
## Environment normalization:
/.bundle
/vendor/bundle
# these should all be checked in to normalize the environment:
# Gemfile.lock, .ruby-version, .ruby-gemset
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
.rvmrc
# if using bower-rails ignore default bower_components path bower.json files
/vendor/assets/bower_components
*.bowerrc
bower.json
# Ignore pow environment settings
.powenv
# Ignore Byebug command history file.
.byebug_history
# Ignore node_modules
node_modules/
Laravel
Laravel は PHP用の MVCフレームワークで、 PHPの中で 人気があるフレームワークの1つです。
Laravel 特有の キャッシュ用の ' storage
' フォルダを含め、環境設定ファイルの ' env ' ファイル、開発用の仮想環境の Homestead の設定ファイルの除外などが記述されています。
vendor/
node_modules/
npm-debug.log
# Laravel 4 specific
bootstrap/compiled.php
app/storage/
# Laravel 5 & Lumen specific
public/storage
public/hot
storage/*.key
.env.*.php
.env.php
.env
Homestead.yaml
Homestead.json
# Rocketeer PHP task runner and deployment package. https://github.com/rocketeers/rocketeer
.rocketeer/
Python
こちらは Python 用 の gitignoreテンプレートです。
Python ファイルを実行した時に生成される '__pycache__
' フォルダを始め、' Django
', ' Flask
' などの Webフレームワーク用の記述もされています。
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
target/
# Jupyter Notebook
.ipynb_checkpoints
# pyenv
.python-version
# celery beat schedule file
celerybeat-schedule
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
# OS
- macOS
- Windows
- Linux
# テキストエディタ || IDE
- Dreamweaver
- Emacs
- Eclipse
- Jetbrain
- SublimeText
- Vim
- Visual Studio Code
- Xcode
# 言語
- C
- C++
- Elixir
- Go
- Java
- Kotlin
- Node.js
- Python
- Ruby
- Rust
- Sass
- Scala
- Swift
# Webフレームワーク
- Cakephp
- Codeigniter
- FuelPHP
- PlayFramework
- Ruby On Rails
- Symfony
- Laravel
- Wordpress
- ZendFramework
# その他 フレームワーク
- Android
- Unity
以上が gitignoreのテンプレート集の紹介でした。テンプレートをコピーしても全ての除外ファイルをカバー出来るわけではありませんが、8割は記述する手間が省けると思います。
また、上記で紹介したのはほんの一部なので、レポジトリページには 言語、フレームワーク問わず様々なテンプレートが用意されています。
GitHub : github/gitignore