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

Solution 1:

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

# Class Files #
*.class

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

Solution 2:

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.