Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ignore all files with the same name in git

Tags:

git

gitignore

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.

like image 678
Chapsterj Avatar asked Jan 24 '12 02:01

Chapsterj


People also ask

How do I ignore a file name in Git?

If you want to ignore a file that you've committed in the past, you'll need to delete the file from your repository and then add a . gitignore rule for it. Using the --cached option with git rm means that the file will be deleted from your repository, but will remain in your working directory as an ignored file.

Can you have multiple Git ignore files?

A . gitignore file is a plain text file where each line contains a pattern for files/directories to ignore. Generally, this is placed in the root folder of the repository, and that's what I recommend. However, you can put it in any folder in the repository and you can also have multiple .


2 Answers

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.

like image 192
Alex.K. Avatar answered Sep 20 '22 20:09

Alex.K.


Update .gitignore with test*

Also, read this for more information.

like image 43
James Raitsev Avatar answered Sep 21 '22 20:09

James Raitsev