.gitignore - Ignore Unwanted Files in Git
A .gitignore file tells Git which files or directories should not be tracked in a repository. This helps prevent unnecessary files—like logs, compiled binaries, and environment variables—from being committed to Git.
1. Creating a .gitignore File
To create a .gitignore file, run:
Then open it in a text editor and add file patterns to ignore.
2. Common .gitignore Rules
š¹ Ignore Specific Files
š This ignores config.json and secret.env in the root directory.
š¹ Ignore All Files of a Type
š Ignores all .log and .tmp files.
š¹ Ignore Directories
š Ignores node_modules, build, and dist directories.
š¹ Ignore Everything Except a Specific File
š Ignores everything in logs/ except logs/important.log.
š¹ Ignore System Files
š Ignores macOS .DS_Store and Windows Thumbs.db.
3. Global .gitignore (For All Repos)
To ignore files globally across all repositories, create a global ignore file:
Then add patterns inside ~/.gitignore_global.
4. How to Check if Git is Ignoring a File?
Use:
If a file is ignored, it will show the matching pattern.
5. Example .gitignore for a Flutter Project
š Prevents tracking of Dart tool files, build directories, and secret keys.
6. What If You Accidentally Tracked an Ignored File?
If a file is already tracked but is now in .gitignore, you need to remove it:
Then commit the changes:
š¹ Conclusion
.gitignore is essential for keeping your Git repository clean and secure. Always add a .gitignore before pushing a project to GitHub! š
Need a .gitignore template for a specific project? Let me know! š

