Post

Setting .gitignore exceptions

Putting an exclamation mark before a filename excludes that file from being ignored.

1
!file1.py

But where an entire directory is being ignored, this exclusion won’t work. I.e. for:

1
2
3
4
my-app/
  └── .gitignore
  └── directory/
        └── file1.py

the following won’t work successfully:

1
2
3
directory

!file1.py

Instead we need to exclude all files in the directory (rather than ignoring the directory itself) using an asterisk - then our exception will work:

1
2
3
directory/*

!file1.py

Ref

This post is licensed under CC BY 4.0 by the author.