Search code examples
gitgitignore

Git Ignore common directories in subprojects


There are multiple git projects (using springboot) under one larger project.

ContainerProject
-.gitignore
  Subproj1/
   -.gitignore
   -target/ 
  Subproj2
   -.gitignore
   -target/ 
 ....

I need to ignore the target folder in all the projects within the .gitignore for the umbrella project. I tried

**/target/
**/target
**/target/*

But none seems to be working for me. git status for the container project still lists changes from these target folders in the sub projects.


Solution

  • Simply do this in your .gitignore:

    target
    

    It should work!

    Example:

    I've above entry (target) in the .gitignore in the following sample tree:

    Test
    - .gitignore
    - abc
      - target/a.txt
      - xyz
        - target/a.txt
    - test
      - target/a.txt
    

    Using git status or from Git GUI, the target directory entries are not visible.