Search code examples
gitgitignore

Is there a convenient way to add all the files exclude the files in .gitignore?


I want to use git to add all the files under the repo exclude the .gitignore contains:

I use git add *, but it will says:

$ git add *
The following paths are ignored by one of your .gitignore files:
media
venv
Use -f if you really want to add them. 

I don't want to add them, and I just want to add the all files exclude the .gitignore write. and looking for a simple way to do that, like add *, but it reports the upper issue. so in my case, I only can add one by one.

Is there a convenient way to realize that?


Solution

  • Running:

    $ git add *
    

    when * matches, say, foo.c foo.h foo.o or foo.cc foo.h foo.o, and your .gitignore says to ignore *.o, produces that warning—but it has added all but the .o file. (Or, in your case, it has added all but media and venv.) So you do not have to do anything different here.

    If you wish to avoid the warning, though, you can run git add . instead. The key difference on a Unix/Linux machine is that git add . will add dot-files, if they are not ignored, that git add * will skip because the shell's expansion of * skips them.