1

I have a git repo with many files and folder but I want to ignore everything except files and folders in a src folder.

This is my .gitignore:

/*

!**/src/
!.gitignore
!README.md

But this is what git status returns:

$ git status
On branch master

Initial commit

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        .gitignore
        README.md

nothing added to commit but untracked files present (use "git add" to track)

So it seems that it is ignoring everything including my src folders.

NecroTheif
  • 284
  • 1
  • 2
  • 12

1 Answers1

2

Make sure to ignore files only, not folders:

*
!*/

It is not possible to re-include a file if a parent directory of that file is excluded (even with 2.7 in your case)

Then you can exclude the folder src files and subfolders content:

!**/src/**
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Omg, thanks so much! This was killing me and I thought it was something simple. Do you need to do !**/src/** ? can't you just do !**/src to include the whole folder? – NecroTheif Nov 10 '15 at 08:41
  • 1
    @NecroTheif `!**/src` would not work, as its content would still be ignored by '`*`'. (I just tested it) – VonC Nov 10 '15 at 08:45
  • Wow, this really works. I have tried many other answers, but none of them really work. – askalee Jul 27 '16 at 10:44