I have been using Netbeans to practice JDBC coding. Netbeans projects create multiple sub-directories (/build, /lib, /src...). Should I add and commit all of these directories and files or should I only choose the java code located in /src?

I am new to Git and have been using YouTube to learn syntax but I have not found anything related to this or generally accepted practices on this matter.

  • 1
    Depends on what you want to keep in your repo. – πάντα ῥεῖ Nov 12 '19 at 17:19
  • @πάνταῥεῖ I honestly don't know what I 'should' be keeping in the repo. Is there some sort of generally accepted practice for this? – CLopes1987 Nov 12 '19 at 17:29
  • Usually you won't keep any binary artifacts in the repo, but even this depends on what you want to publish. There's no general rule. – πάντα ῥεῖ Nov 12 '19 at 17:31
  • @πάνταῥεῖ ok, thank you – CLopes1987 Nov 12 '19 at 17:44

Everything that that another developer would need to compile / run your code without modification (with the possible exception of passwords and secrets).

You should look into .gitignore files. You can find .gitignore files suitable for specific languages and frameworks here:


You may take the simplistic view that if it's not in the appropriate .gitignore file for your domain, you can commit it.

| improve this answer | |
  • 1
    Less simplistically: don't commit what can be produced from source (e.g. commit the manual.md you've written, but not the manual.pdf you've generated from it. Same with code/binaries, etc). For .gitignore files, you can also go to gitignore.io – doubleYou Nov 16 '19 at 13:55

You should find NetBeans creates its own .gitignore file, which ensures the files you don't want in your repo will get ignored by git automatically without you having to manage it through watching what you add and commit. You can pretty much then commit the entire project folder and let git do its thing.

On my projects, those are set to

/[project folder]/nbproject/private/
/[project folder]/build/
/[project folder]/dist/

Depending on your NetBeans version and various settings, this may be slightly different, for example it could be a .gitignore in the project folder that reads


These settings ensure the private section of the nbproject folder (which contains Netbeans-specific project files that should not be shared between machines), the build folder (where java classes compiled from your source are stored), and the dist folder (where the final compiled distributable files of your project end up) are kept out of source control (which only needs the source files necessary to recompile those files)

Don't just commit /src/ unless you really don't mind that you'll not be keeping your NetBeans project files in git. You may also find out you're missing other things such as a resources folder or any other options you've added if you do this, so I recommend committing the entire project folder - NetBeans is designed to deal with what does and doesn't go into git if you do this.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.