Zunaed Karim Sifat
Zunaed Karim Sifat

Reputation: 11

Ignoring files containing no period in git

I want to ignore all the files in my git repository whose name does not contain any '.' (period). How to make git ignore them?

Upvotes: 0

Views: 62

Answers (1)

torek
torek

Reputation: 489083

  1. Ignore everything: *

  2. Un-ignore directories, so that Git will look inside directories: !*/

  3. Un-ignore files with at least one dot: !*.*

The resulting .gitignore consists of those three lines, in that order:

$ cat .gitignore
*
!*/
!*.*
$ git ls-files --other
.gitignore
foo
foo.txt
sub/bar
sub/bar.y
$ git status --short -uall
?? .gitignore
?? foo.txt
?? sub/bar.y

(While this does work, it may not be the best overall strategy: as Yunnosch suggested in a comment, it might be better, strategically, to put the generated binaries elsewhere.)

Upvotes: 2

Related Questions