【.gitignore】How to specify a path, what to do if it does not reflect, etc.


This article is a personal note related to .gitignore.

Specify path

# ignore .txt hoge message
# Ignore hoge directory
# Ignore hoge directory

The directory ignored changes first by whether or not to add “/”.

If / is attached first, the directory specified in the relative path from .gitignore is ignored. If / is not attached first, all directories will be searched and the specified directory will be ignored.

Wildcards and nega denying

# .txt all files in the file

# Don't ignore hoge directories

* can be used with all, and ! can be used for negation. You can also use ? and [0-9] can also be used.

Specific extension files in a specific directory

# Ignore .txt files in hoge

When you edit .gitignore but it is not reflected

Causes and solutions for .gitignore but their edits are not reflected.


It was due to the addition of something once uploaded to git to .gitignore. In short, I made a commit and pushed it before editing.

Apparently, the .gitignore setting was not reflected because there is still an index in the cache.



  1. .gitignore Edit
  2. Delete cache
  3. commit & push

Delete cache

# Delete entire file cache
$ git rm -r --cached .
# Delete cache by specifying a file
$ git rm -r --cached [ファイル名]

Run the above command.

Ensure that the entire file cache is deleted. I haven’t thought of a point where I’m bothering to delete by specifying a file.


[Git] .gitignoreの仕様詳解 - Qiita
対応バージョン この記事の内容は、少なくともGitのバージョン2.19.1までは対応している。 もし最新のGitで新しい動きがあれば随時更新する。 基本 .gitignoreを使うと無視する(Gitのトラッキングの対象外と...