LoginSignup
65
62

More than 5 years have passed since last update.

複数人で開発するとき git 管理から外す指定方法 3 パターンの使い分け

Last updated at Posted at 2015-01-15

周りを眺めてると意外とプロジェクトルートの gitignore に環境依存の指定を大量に書いてるプロジェクトや、「exclude は知らなかった」とかのケースあったので、まとめてみる。

gitignore (global)

  • ホームディレクトリ内に置いといたファイル内容を、全 git プロジェクトで共通して除外指定するやり方
  • 利用シーン
    • 自分の環境に依存する
    • 特定のプロジェクトに依存せず無視したい
    • .DS_Store
    • Thumbs.db
    • Session.vim

global な gitignore の設定方法

方法1

OSX の場合 $HOME/.config/git/ignore を配置して書いていけばOK。

$ man gitignoreGit - gitignore Documentation を確認すると、次のように書いてあるので、デフォルトにならうことにした。

Its default value is $XDG_CONFIG_HOME/git/ignore. If $XDG_CONFIG_HOME is either not set or empty, $HOME/.config/git/ignore is used instead.

方法2

よくみかける設定方法はこっち。

$ git config --global core.excludesfile $HOME/.gitignore_global

とすると

~/.gitconfig
[core]
    excludesfile = /home/${USERNAME}/.gitignore_global

と追記される。

gitignore (local)

  • GIT_PROJECT_ROOT/.gitignore に無視したい対象を書いていく、一番ポピュラーなやり方
  • 利用シーン
    • プロジェクト依存
    • 開発者間で無視する対象を 共有したい
    • .rspec
    • /log
    • /tmp

開発者の環境依存なファイルは global なほうの gitignore で、というルールにしてしまえば、完全にそのプロジェクト固有で無視したいものだけを書けるのですっきりする

exclude

  • GIT_PROJECT_ROOT/.git/info/exclude に書くやり方
  • 利用シーン
    • プロジェクト依存
    • 開発者間で無視する対象を 共有したくない

プロジェクト依存なので global な gitignore に書きたくないけど、共同作業してる開発者に共有するかんじでもない、みたいなときに

いまのところ僕は使ったことない

参考

65
62
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
65
62