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

61,061

Solution 1

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.

Solution 2

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?

Solution 3

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.

Share:
61,061

Related videos on Youtube

B Seven
Author by

B Seven

Status: Hood Rails on HTTP/2: Rails HTTP/2 Rack Gems: Rack Crud Rack Routing Capybara Jasmine

Updated on March 08, 2020

Comments

  • B Seven
    B Seven about 4 years

    Can you create a .gitignore file in a directory that only applies to files (and directories) within that directory?

  • dsula
    dsula over 2 years
    Does the .gitignore in the subdirectory replace the root .gitignore? Or does it add to it?
  • Mike Morearty
    Mike Morearty about 2 years
    @dsula the .gitignore in the subdirectory adds to the root .gitignore (does not just replace it).