Ignore all files with the same name in git

GitGitignore

Git Problem Overview


Is there a way to have a git ignore file to ignore all files with the name test in them?

I have files like this:

 - css/test.css 
 - js/subfolder/test.js 
 - lib/main/sub/test.html

and so on.

I want git to avoid adding or committing any files with the name test.

Git Solutions


Solution 1 - Git

From git docs

A leading "**" followed by a slash means match in all directories. For
example, "**/foo" matches file or directory "foo" anywhere, the same
as pattern "foo". "**/foo/bar" matches file or directory "bar"
anywhere that is directly under directory "foo".

For your case:

**/[Tt]est*

it also matches both upper and lower case.

Solution 2 - Git

Update .gitignore with test*

Also, read this for more information.

Solution 3 - Git

Try adding the pattern to .gitignore of test.*

Add it and do a git status with some files like you mentioned above.

If it works you're good.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionChapsterjView Question on Stackoverflow
Solution 1 - GitAlex.K.View Answer on Stackoverflow
Solution 2 - GitJames RaitsevView Answer on Stackoverflow
Solution 3 - GitDave GView Answer on Stackoverflow