Git .gitignore

Keep files out of the repository.

✍️ 2 exercises in this lesson

A .gitignore file lists files and folders Git should never track: dependencies, build output, logs and secrets.

  • node_modules/, vendor/: installed packages
  • .env: secrets and passwords
  • *.log: any file ending in .log
  • /build: only the build folder in the root
  • !keep.log: an exception
If a file was already committed, ignoring it is not enough. Remove it from tracking with git rm --cached file.

Key Takeaways: Git .gitignore

Mastering Git .gitignore helps you write clean and reliable Git code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.

Git .gitignore Code Example

Git
# Dependencies
node_modules/
vendor/

# Environment & secrets
.env

# Logs and build output
*.log
/dist
/storage/*.key

# OS files
.DS_Store
Thumbs.db
Run this example on your own computer. The "Get Started" lesson shows how to set it up.

Git .gitignore Practice Exercises

Check what you learned in “Git .gitignore”.

/ 2 solved
Fill in the blank

Ignore every file ending in .log.

✓ Correct! Not quite. Try again.
Multiple choice

A file was already committed. How do you stop tracking it?

✓ Correct! Not quite. Try again.
to save your exercise progress.
Finished this lesson?
Mark it complete to track your progress.

Stuck on something?

Ask the community in the CodesInTech forum.

Need a developer?

Learning on your own is great — and when you need professional help, our team builds custom software, websites and mobile apps for clients worldwide.

Explore Our Services