Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

With git, how can I perform a git add and still have it ignore the patterns in .gitignore?

Tags:

git

I want to do something like git add *.java and not let it throw up just because one of those files matched the .gitignore.

For example: In my directory I have

ignored.java
something.java
somethingelse.java 
somethingevenmoreelse.java.

where the three last files were just created by me. I then want to do git add *.java

and have it add those three files. In other words, instead of giving me

The following paths are ignored by one of your .gitignore files:
ignored.java
Use -f if you really want to add them.
fatal: no files added

... I would rather it would just ignore the .gitignored files and add the rest.

like image 373
Christian Neverdal Avatar asked Feb 02 '23 08:02

Christian Neverdal


1 Answers

If you quote the glob pattern then it will interpreted by git instead of the shell and it will ignore the ignored files before adding the rest without error.

git add '*.java'

alternatively:

git add \*.java
like image 64
CB Bailey Avatar answered Feb 05 '23 04:02

CB Bailey