Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is it possible to ignore .gitignore rules in subdirectory?

Tags:

git

I want to ignore all of .gitignore rules in subdirectory except .gitignore rules in root.

for example) I have already .gitignore file in a directory structure /a.

And also have .gitignore file in /a/b. Assume /a have a.txt b.txt files.

/a/b has .config file. .gitignore defines .config in /a/b.

.config file will be ignored by .gitignore in /a/b.

But I really want to track .config file by ignoring rules of .gitignore in subdirectory.

Is it possible?

Thanks in advance

like image 572
john Avatar asked Sep 15 '10 16:09

john


People also ask

Does Gitignore apply to subdirectories?

gitignore file is usually placed in the repository's root directory. However, you can create multiple . gitignore files in different subdirectories in your repository.

Can you ignore the Gitignore?

gitignore , nor in the global . gitignore , can be ignored using explicit repository excludes in your_project_directory/. git/info/exclude . This file will not be shared with other developers, and is specific for that single repository.

Does Gitignore need to be in every folder?

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 .

How do I ignore a .gitignore class file?

The easiest and most common way to ignore files is to use a gitignore file. Simply create a file named . gitignore in the repository's root directory. Then, add names and patterns for any files and directories that should not be added to the repository.


2 Answers

Your question isn't too clear, but if there are some subdirectories where you want different gitignore rules, you can just create a new .gitignore in that directory.

Say you have:

 project/.gitignore project/stuff/.gitignore 

The .gitignore in stuff/ will override the .gitignore in the root directory.

git help gitignore or man gitignore has quite a bit more information about what's possible.

like image 157
signine Avatar answered Sep 21 '22 03:09

signine


Lets say you want to include node_modules in your repository, but some module down the line has .gitignore of its own. You can negate the rules by adding the following to your root .gitignore file:

# Make sure to include everything in node_modules. !node_modules/** 
like image 26
Nick Zalutskiy Avatar answered Sep 22 '22 03:09

Nick Zalutskiy