[Git] グローバルな .gitignore で全ての git リポジトリで無視するファイルを設定する方法

Git にて .DS_Store のような無視したいファイルを間違ってコミットしてしまわないように、全てのリポジトリに適用される .gitignore を作成しました。

Git

~/.gitignore の作成・編集

echo .DS_Store >> ~/.gitignore

git にホームディレクトリ以下の .gitignore を使う設定

git config --global core.excludesfile ~/.gitignore

これで、ホームディレクトリ以下の.gitignore で指定したファイルが全ての git リポジトリで無視されるようになりました。

ちなみに、git init で自動で生成される .gitignore にもちゃんと書いてあります。

# If you find yourself ignoring temporary files generated by your text editor
# or operating system, you probably want to add a global ignore instead:
#   git config --global core.excludesfile ~/.gitignore_global

以上です。

参考情報

Gitを使い始めたらやっておきたい便利な設定いろいろ : アシアルブログ

グローバルな.gitignore を設定して、すべてのgitリポジトリで無視するファイルを設定する|WEBデザイン Tips