Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you have additional .gitignore per directory within a single repo?

People also ask

Can you have multiple Gitignore files in a repo?

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 .

Can I have Gitignore in subdirectory?

gitignore in every subdirectory. This way you can ignore files on a finer grained level if different folders need different rules. Moreover, you can define repository specific rules which are not committed to the Git repository, i.e. these are specific to your local copy.

Can you have nested Gitignores?

You can nest gitignores in a project to have per directory ignore files. e.g. Now a/b/. gitignore can handle any ignoring in subdirectory b .


Yes, you can. Try it, it works fine. Put a .gitignore in the root of your repo, and put another .gitignore with additional things to ignore in a subdirectory.


Similar question was: Are multiple `.gitignore`s frowned on? (Jul 2010)

Or if you can have different version of a .gitignore file per branch: Using github to host public git repositories whilst ensuring that sensitive data files remain untracked (Feb 2010)

Further perhaps related: How do I tell git to always select my local version for conflicted merges on a specific file?


You can just specify files to ignore in a format such as

Xyz/*.abc

in the .gitignore in the root directory, potentially removing the need for separate ignore files.