You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: site/posts/understanding-gitignore/index.qmd
+57Lines changed: 57 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -47,6 +47,52 @@ For complete syntax please refer to the [official documentation](https://git-scm
47
47
48
48
These rules are applied whenever Git checks for changes, so you only see relevant modifications.
49
49
50
+
## About Multiple .gitignore Files
51
+
52
+
It's worth noting that it is possible to have multiple .gitignore files throughout the project. .gitignore files are not limited to just one in the root directory. When we place a .gitignore file in a subfolder, Git applies those specific ignore patterns only within that folder.
53
+
54
+
This is particularly useful for tools like R's renv package or Python's virtual environments, which might have their own temporary files and configurations that should be ignored at different levels of project structure.
Then add common patterns in .gitignore_global file located at ~/ (home directory) that should be ignored across all projects.
109
155
156
+
## Important Limitation
157
+
158
+
While .gitignore is powerful, it has an important limitation: it won't ignore files that are already included (staged or committed) in Git. If a file is added to the staging area with `git add`, Git will continue tracking it even if it matches patterns in existing .gitignore file.
159
+
160
+
If such a file is already included and needs to be excluded, this need to explicitly remove it from tracking using:
161
+
```
162
+
git rm --cached filename
163
+
```
164
+
165
+
This removes the file from version control but leaves it on the local filesystem.
166
+
110
167
## Best Practices
111
168
112
169
1.**Create early**: Add .gitignore at the beginning of a project
0 commit comments