Git Ignores and Maven targets

Anyone know if it is possible to ignore all the instances of a particular directory in a file structure managed by git.

I’m looking to exclude all the ‘target’ folders in a maven project with a number of submodules. I know I can explicitly exclude each of them in a top level .gitignore, but I’d really like to be able to specify a pattern like **/target/* there to have it automatically ignore the instance in sub directories?

  • git: can I subtree merge just a subpath of a repository?
  • How do I get git to recognize mailmap for users without email-adresses?
  • libiconv.2.dylib Mountain Lion issue
  • Undo git checkout --orphan
  • After moving files/directories, GitHub shows no history for the files but Git does - is this due to how I moved them?
  • Enable requests to .git/HEAD in IIS
  • Is this possible?

  • Can Git detect if two source files are essentially copies of each others?
  • Git: The Curious Case of the Missing Commits
  • Gitolite asking for git ssh password on localhost
  • How do I install and use MySQLdb for Python 3 on Windows 10?
  • Git. Keep stable and dev versions of project
  • git + ssh > remote empty, tree and non-bare
  • 3 Solutions collect form web for “Git Ignores and Maven targets”

    It is possible to use patterns in a .gitignore file. See the gitignore man page. The pattern */target/* should ignore any directory named target and anything under it. Or you may try */target/** to ignore everything under target.

    The .gitignore file in the root directory does apply to all subdirectories. Mine looks like this:

    .classpath
    .project
    .settings/
    target/
    

    This is in a multi-module maven project. All the submodules are imported as individual eclipse projects using m2eclipse. I have no further .gitignore files. Indeed, if you look in the gitignore man page:

    Patterns read from a .gitignore file
    in the same directory as the path, or
    in any parent directory

    So this should work for you.

    As already pointed out in comments by Abhijeet you can just add line like:

    /target/**
    

    to exclude file in \.git\info\ folder.

    Then if you want to get rid of that target folder in your remote repo you will need to first manually delete this folder from your local repository, commit and then push it. Thats because git will show you content of a target folder as modified at first.

    Git Baby is a git and github fan, let's start git clone.