We have a deep directory structure with multiple README files at different levels. For instance:
gitignoretest/
|-- 00README
|-- dir1
|   |-- 00README
|   |-- dir1
|   |   |-- 00README
|   |   |-- dir1
|   |   |-- dir2
|   |   |-- dir3
|   |   |-- file1
|   |   `-- file2
|   |-- dir2
|   |   |-- 00README
|   |   |-- dir1
|   |   |-- dir2
|   |   |-- dir3
|   |   |-- file1
|   |   `-- file2
|   |-- dir3
|   |   |-- 00README
|   |   |-- dir1
|   |   |-- dir2
|   |   |-- dir3
|   |   |-- file1
|   |   `-- file2
|   |-- file1
|   `-- file2
|-- dir3
|   |-- 00README
|   |-- dir1
|   |   |-- 00README
|   |   |-- dir1
|   |   |   |-- 00README
|   |   |   |-- dir1
|   |   |   |-- dir2
|   |   |   |-- dir3
|   |   |   |-- file1
|   |   |   `-- file2
|   |   |-- dir2
|   |   |   |-- 00README
|   |   |   |-- dir1
|   |   |   |-- dir2
|   |   |   |-- dir3
|   |   |   |-- file1
|   |   |   `-- file2
...
...
We want to ONLY version the 00README files. We successfully tested this with this .gitignore
.gitignore
# Ignore everything
*
# But not these files...
!.gitignore
!00README
# etc...
# ...even if they are in subdirectories
!*/
However, in the real scenario, one of the subdirectories is a conda installation which has some packages containing their own .git directories. When I do git add . it fails with the message:
fatal: Not a git repository: Applications/conda/lib/STAR-Fusion/STAR-Fusion.wiki/../.git/modules/STAR-Fusion.wiki
The real scenario is ../TopLevel/Applications/... with ../TopLevel/.gitignore. Here are the things I've tried:
../TopLevel/.gitignore
# Ignore everything
*
/Applications/conda/**/*
/Applications/miniconda3/**/*
/Applications/newconda/**/*
Applications/conda/**/*
Applications/miniconda3/**/*
Applications/newconda/**/*
/**/.git
**/.git
/**/.git/**
**/.git/**
# But not these files...
!.gitignore
!00README.md
!USE_APPS
# etc...
# ...even if they are in subdirectories
!*/
But not hitting the mark.
EDIT
To address the issue of "untracking" subdirectories with .git folders as mentioned by @VonC, I present a completely fresh creation of the git repository. Note: the repository being added as the remote is a freshly minted --bare repository.
balter@server:/home/.../TopLevel$ rmdir .git
balter@server:/home/.../TopLevel$ git init
Initialized empty Git repository in /home/.../TopLevel/.git/
balter@server:/home/.../TopLevel$ git remote add origin git@server.ohsu.edu:path/repo.git
balter@server:/home/.../TopLevel$ git status
# On branch master
#
# Initial commit
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   .gitignore
#   00README.md
#   Applications/
#   InstallationPackages/
#   USE_APPS
#   gitignoretest/
nothing added to commit but untracked files present (use "git add" to track)
balter@server:/home/.../TopLevel$ git add .
fatal: Not a git repository: Applications/conda/lib/STAR-Fusion/STAR-Fusion.wiki/../.git/modules/STAR-Fusion.wiki
 
     
    