Video in progress
What is the `.gitignore` file for, and what usually goes into it in a Java project?
.gitignore lists files Git should not track: build output, IDE settings, local secrets, logs. That way they do not end up in a commit by accident.
📖 Answer
A typical example for a Java/Spring project:
# build output
target/
build/
*.class
# IDE
.idea/
*.iml
.vscode/
# local settings and secrets
.env
application-local.yml
# logs and OS junk
*.log
.DS_Store
The rule: anything generated (that reappears when you build) does not go into the repository. The Maven wrapper (mvnw, .mvn/wrapper) is the opposite: it is committed, because others need to build with the same version.
One catch: .gitignore affects only files that are not tracked yet. If a file was committed earlier, adding it to the list is not enough. You first have to remove it from the index with git rm --cached.
Sign up to mark studied questions and save your progress.