3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

.gitignoreではなくて、個人的にgit追跡から省きたいファイル、フォルダを設定する方法 | .gitignore_global, .git/info/exclude

Last updated at Posted at 2025-07-18

.gitignoreは、プロジェクトによってはリモートリポジトリで変更履歴をとっているので、個人的に省きたいファイルやフォルダを書き込むのが難しいという場面があります。そういう時に便利な .gitignore_global.git/info/excludeを紹介します。

変更履歴に残り続けていても気にならない人、またはプロジェクトによってリモートリポジトリの追跡対象に.gitignoreが入っていないプロジェクトでは今回の内容はあまり参考にならないかもしれません。

使用しているPC上で、常に追跡を逃れたい…そんな時は~/.gitignore_global

新しいPCを使い出した時はこの~/.gitignore_globalに書いておけば、そのPC内ではいちいちプロジェクトファイルを作ったときに.gitignoreを書かなくて済むようになります。

macだと.DS_Storeや、AIエージェント関係のものは常にGitの追跡を逃れさせたいのではないでしょうか?そんな時には私は以下のように書いています。

~/.gitignore_global
.DS_Store
copilot-instructions.md
CLAUDE.md
claude-log/
.claude/
.vscode/

プロジェクト単位で.gitignoreを使わず追跡を逃れる定義をしたい…そんな時は.git/info/exclude

プロジェクト単位で追跡対象外にしたいディレクトリやファイルを指定する場合、有名なのは.gitignoreに定義する方法ですが、プロジェクトによっては.gitignoreがリモートリポジトリの追跡対象で、個人で.gitignoreを変更すると、変更履歴に載ってしまって邪魔になる…ということありますよね。

そんな時はプロジェクトファイルの.git/info/excludeに書き込んで定義しましょう。
このファイルは.git以下にあり、もともとGit追跡対象外なので、変更しても変更履歴に載りません。

.git/info/exclude
.DS_Store
copilot-instructions.md
CLAUDE.md
claude-log/
.claude/
.vscode/
3
4
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
3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?