Adding File Exclusion Rules
- Open the `.gitignore` file in a text editor.
- Add lines with patterns specifying the files you want to exclude. Here are some common patterns:
- `*`: This wildcard excludes all files in the current directory.
- `filename`: Excludes a specific file named “filename“.
- `folder/*`: Excludes all files inside a specific folder named “folder“.
- `.gitignore`: Excludes the `.gitignore` file itself (handy to prevent accidental tracking).
- Example :
Let’s say you only want to track “README.md” and “index.html” in your project:
# Ignore all files except "README.md" and "index.html"
*
!README.md
!index.html
How to Make .gitignore Ignore Everything Except a Few Files?
Sometimes you might have files in your Git project that you don’t want tracked by version control. Here’s how to use a `.gitignore` file to tell Git to ignore everything except a few specific files you want to keep track of.
Table of Content
- Creating the `.gitignore` File
- Adding File Exclusion Rules
- Saving and Checking
- Keep in Mind