Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Subfolders in .gitignore

Tags:

git

gitignore

I have many subfolders in my repo, in which there are few build/ directories I'd like to ignore when committing my code. As I understand it, there are two ways to ignore all of the folders:

  • */build/ (Unix wildcards)
  • build/ (git way of ignoring files/folders)

I've found Git ignore sub folders but it has two answers and I would like to know what the difference (none?) between the two approaches is. Does the same rule apply to files?

like image 269
syntagma Avatar asked Feb 24 '13 22:02

syntagma


1 Answers

build/ is the right way to do it. It will ignore any files that are inside build directories no matter how deep are these directories nested in your repo.

*/build/ means ignore build directories that are exactly one level deep inside your repo. So for instance files inside build and foo/bar/build won't be ignored.

If you need more fine grained control, you can always add specific directories to exclude but also not to exclude using ! as a prefix.

like image 72
Simon Avatar answered Sep 28 '22 02:09

Simon