Search code examples
gitvisual-studiogitignoreprojects-and-solutions

.gitignore with Visual Studio Solutions containing multiple project folders


I have a c:\git folder where I store all my code. In this folder is a folder for each application/solution. Each application/solution can have many projects.

Example folder structure:

c:\git\abc\abc-da\
c:\git\abc\abc-WebUI\
c:\git\abc\abc-WinService\
c:\git\abc\abc-Tester\
c:\git\abc\abc-UnitTest\

My question is this:
If I put my VisualStudio.gitIgnore file in the c:\git\abc\ folder (named .gitignore obviously) then would it apply to all subfolders? or do I have to copy the .gitignore to each project folder?


Solution

  • .gitignore applies to a project from the root, and matches children via the glob search. Additionally, any .gitignore files in children directories from the root of a project, will apply the same. This stops once you hit a .git directory (the indicator for the start of a repo).

    Separately from that, you can set a global .gitignore file that Git will apply to all projects under a particular git installation (or, installations referencing that file).

    git config --global core.excludesfile ~/.gitignore
    

    Usually this goes in your home folder as ~/.gitignore or ~/.gitignore_global and is used to ignore files related to your personal setup (ie, you use IntelliJ? Ignore .idea, don't ignore it on every project).

    Beyond that, I do not believe Git has additional builtin functionality for .gitignore.

    Fantastic references: