1

I have the following .gitignore file:

# Ignore everything
*

# But not these
!.gitignore
!Code
!Materials

The intention is to ignore everything except the .gitignore file itself, and everything under the Code and Materials directories. Somehow when I open SourceTree, the .gitignore file is properly excluded, but the Code and Materials directories are ignored. What did I do wrong?

Ry-
  • 218,210
  • 55
  • 464
  • 476
CaTx
  • 1,421
  • 4
  • 21
  • 42
  • Possible duplicate of [.gitignore exclude folder but include specific subfolder](https://stackoverflow.com/questions/5533050/gitignore-exclude-folder-but-include-specific-subfolder) – phd Jan 24 '18 at 02:29

1 Answers1

3

* matches every file in those directories as well (and Git doesn’t keep track of empty directories). You can ignore just the top level:

# Ignore everything
/*

# But not these
!/.gitignore
!/Code
!/Materials

Paths like /Code/example.cs won’t be matched by /*, because * can only represent one path component, but a simple * without the / will match the example.cs component of /Code/example.cs.

Ry-
  • 218,210
  • 55
  • 464
  • 476