Create a Git Ignore File
1. Using your preferred code editor, create and save an empty file named .gitignore in the root directory of your Git repository. This critical file tells Git which files and directories to exclude from version control tracking.
NOTE: On Unix-based operating systems like macOS and Linux, files beginning with a period (.) are treated as hidden system files. While the .gitignore file won't appear in macOS Finder or standard file browsers without enabling "Show Hidden Files," all modern code editors display it by default. This hidden nature is by design—configuration files like .gitignore are meant for developers, not end users.
2. Populate this file with patterns matching files you want Git to ignore. Professional developers typically exclude operating system artifacts, build outputs, dependency folders, and sensitive configuration files. Here's a foundational example covering common system files:
# macOS system files
.DS_Store
.DocumentRevisions-V100
.Spotlight-V100
.Trashes
# Windows system files
Thumbs.db
Desktop.ini
Setting Up Your .gitignore File
Create the file
Using your code editor, save an empty file named .gitignore into the root folder of your Git repository
Add ignore patterns
List any files or patterns you want Git to ignore, starting with common system files
Save and commit
Save the .gitignore file and commit it to your repository so all team members benefit
Files starting with a period are hidden on Unix-based systems like macOS. You won't see .gitignore in Finder unless you show hidden files, but it will be visible in most code editors.
Common Files to Ignore
Mac System Files
.DS_Store files are created automatically by macOS and contain folder metadata. These should never be committed to version control.
Windows System Files
Thumbs.db files store thumbnail cache data on Windows systems. Including these in repositories adds unnecessary bloat.
Document Revisions
Files like .DocumentRevisions-V100 and .Spotlight-V100 are macOS system files that track document versions and search indexing.
Syntax For .gitignore
Understanding .gitignore syntax is essential for maintaining clean repositories and protecting sensitive data. The file supports wildcards, directory patterns, and exception rules that give you precise control over what Git tracks.
- Git-scm.com/docs/gitignore - Official Git documentation with comprehensive syntax reference
- Atlassian.com/git/tutorials/saving-changes/gitignore - Practical examples and best practices from Atlassian's Git experts
Essential .gitignore Resources
Official Git Documentation
The authoritative source at Git-scm.com provides comprehensive documentation on .gitignore syntax and advanced patterns.
Atlassian Git Tutorials
Practical tutorials from Atlassian offer real-world examples and best practices for implementing .gitignore effectively.
Best Practices Checklist
Ensures patterns apply to the entire project structure
Prevents accidentally ignoring important files
Helps team members understand why certain files are ignored
Verify that intended files are properly excluded
Go Beyond Git
Master Git and expand your development expertise with our comprehensive programming education. Our industry-focused courses combine hands-on coding practice with real-world project experience, guided by experienced instructors who understand today's development landscape. Each program includes detailed workbooks and step-by-step exercises designed for immediate practical application.
Comprehensive Programming Education
Web Development Courses
Master modern web technologies with hands-on training in NYC. Build real applications while learning industry best practices.
Python Programming
Learn Python from fundamentals to advanced concepts. Perfect for beginners and experienced developers expanding their skillset.
Data Science Training
Comprehensive data science curriculum covering analytics, machine learning, and statistical modeling with real-world applications.
Web Design Courses
Develop design skills alongside technical knowledge. Learn to create beautiful, functional user interfaces and experiences.
All courses feature practical exercises with step-by-step workbooks and real-world applications, ensuring students gain applicable skills for immediate use in their careers.