11. .gitignore & Repository Best Practices
.gitignore & Repository Best Practices
A well-maintained Git repository is a professional asset. A poorly configured one leaks secrets, bloats with build artefacts, and creates confusion. These practices are the difference between a repository that teams trust and one they dread working with.
🚫 The .gitignore File
The .gitignore file tells Git which files and folders to completely ignore — never stage, never commit, never track. Create it in the root of your repository:
Inside your .gitignore file, add content like this:
Add the file to git and commit:
📋 Repository Hygiene Checklist
- README.md at root: What is this project? How do you set it up? How do you run it? How do you run the tests? This is the first file any new developer reads.
- LICENSE file: Defines how others can use, modify, and distribute your code. Without a license, the default is all rights reserved.
- CONTRIBUTING.md: Guidelines for how to submit pull requests and issues to open-source projects.
- No build artefacts committed:
node_modules/,dist/,__pycache__/should never be in the repository. - No binary files if avoidable: Git is designed for text. Large binaries (images, compiled binaries, databases) bloat repository size permanently and slow down clones.
📏 Commit Frequency Best Practices
Commit small and often — one logical unit of work per commit. Small commits equal easier code review, make it easier to identify which commit broke something, and are easier to cherry-pick or revert specific changes.
BAD: commit everything at end of day:
GOOD: commit each logical change as you complete it:
Knowledge Check
Ready to test your understanding of 11. .gitignore & Repository Best Practices?