0

I have a directory structure like this for dr1:

.
├── dr2
│   ├── hi.txt
│   └── inputs
│       ├── anotherbigfile.big
│       └── bigfile.big
├── dr3
│   ├── bye.txt
│   ├── inputs
│   │   ├── anotherbigfile.bigfile
│   │   └── bigfile.bigfile
│   └── small.txt
└── dr4
    └── bye.txt

My dr1 is a git repo with .gitignore with the following contents:

inputs/

I want to stage everything in dr1 , I mean all sub-directories and all files , I just want to not stage, commit and push the inputs directory in every sub-directory dr2 dr3 dr4. These contain big files and I don't them in github.

I did this git add . from dr1 but I am having a problem since only the sub-directories are being staged but not the contents, so in my repo I only have empty directories, only the dr4 sub directory works since there is no folder with inputs there. What's wrong here ? I thought git would ignore only the sub-directory input but the rest of the directory would be staged

moth
  • 1,833
  • 12
  • 29
  • Does this answer your question? [How to git ignore subfolders / subdirectories?](https://stackoverflow.com/questions/2545602/how-to-git-ignore-subfolders-subdirectories) – flaxel Nov 30 '20 at 07:24
  • I can't reproduce on my machine. Did you post the complete content of your `.gitignore` ? Run `git check-ignore -v **/*` to check if the other files are skipped because of some ignore rules. – LeGEC Nov 30 '20 at 08:05
  • "only the sub-directories are staged" doesn't make much sense : git doesn't track empty directories. Are these directories submodules ? or symbolic links on your file system ? – LeGEC Nov 30 '20 at 08:06

1 Answers1

1

You can use wildcards.

You can add the next lines to your .gitignore file:

dr2/inputs/
dr3/inputs/

If you don't want to be specific and quite sure that you won't need to commit any input subfolder in the future than you can use:

**/inputs/

in your .gitignore.

Valerii Boldakov
  • 1,751
  • 9
  • 19
  • hum ok makes sense. why the double asterisk `**` instead of a single one ? – moth Nov 30 '20 at 07:28
  • @alex `**` matches any character zero or more times, including `/`. So it will ignore the `inputs` folder in *any* subdirectory. You can replace it with `*` if you want to ignore only `inputs` subfolders of your upper-level subfolders. – Valerii Boldakov Nov 30 '20 at 07:31
  • What's the output for the `git status` command? And what your `.gitignore` look like? – Valerii Boldakov Nov 30 '20 at 07:44
  • nothing to commit is the output. and my `.gitignore` is dr2/inputs/ dr3/inputs/ – moth Nov 30 '20 at 07:48
  • I use `git add .` from `dr1` but it's still not tracking after the `gitignore` modification – moth Nov 30 '20 at 07:49
  • That's weird. It looks like git doesn't see any not ignored files. Can you please modify any not ignored file and tell me what's `git status` output? – Valerii Boldakov Nov 30 '20 at 07:51
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/225307/discussion-between-valerii-boldakov-and-alex). – Valerii Boldakov Nov 30 '20 at 07:53