what should be in .gitignore file for a netbeans java project?

GitNetbeansGitignore

Git Problem Overview


What should be the content of the .gitignore file for a java project in netbeans?

Git Solutions


Solution 1 - Git

# NetBeans specific #
nbproject/private/
build/
nbbuild/
dist/
nbdist/
nbactions.xml
nb-configuration.xml

# Class Files #
*.class

# Package Files #
*.jar
*.war
*.ear

Solution 2 - Git

There are a fair number of files that you probably do not need to commit into git, since they are built, are generated by NB or contain environment specific information.

If you create a project that uses Ant as the build mechanism, you usually end up with a directory tree that looks like this...

project-root-directory/
+ nbproject/
  build-impl.xml
  + private/
  + project.properties
  + project.xml
+ src/
+ test/
+ build.xml

After you do a build.. there will be a couple additional directories

project-root-directory/
+ build/
+ dist/
+ nbproject/
  build-impl.xml
  + private/
  + project.properties
  + project.xml
+ src/
+ test/
+ build.xml

You should probably put the build, dist and nbproject/private directories (and their children) into your .gitignore.

If you want to be very aggressive about excluding files, you may want to consider excluding all the files that appear in nbproject EXCEPT project.properties and project.xml. The other files in the nbproject directory are regenerated by NetBeans when the project is opened.

Solution 3 - Git

There should be no NetBeans-specific files in your .gitignore. The .gitignore file is project-specific but shared between developers, IOW there should only be things in there that are common for all developers working with the code (including ones that use OSX, Linux instead of Windows and Eclipse, IntelliJ or Notepad as editors) and that are specific to the project.

If there are some files that you would like to ignore based on your specific environment (like e.g. Windows Thumbs.db and desktop files or NeBeans nbproject directories) you should do that in your global ignore list, not in the project-specific .gitignore – if only because then you don't need to add them to every single of your projects individually.

If the files you want to ignore are both specific to your environment and specific to the project, put them into that repository's .git/info/exclude.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionthuasoView Question on Stackoverflow
Solution 1 - Gitmono68View Answer on Stackoverflow
Solution 2 - GitvkraemerView Answer on Stackoverflow
Solution 3 - GitJörg W MittagView Answer on Stackoverflow