Skip to content

Commit 18a3103

Browse files
committed
Mostly cosmatic changes in codeblocks. Renamed a section to Important Note from Important Limitation.
1 parent ef1d1f8 commit 18a3103

File tree

1 file changed

+29
-31
lines changed

1 file changed

+29
-31
lines changed

site/posts/understanding-gitignore/index.qmd

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,23 @@
22
title: "Understanding gitignore: A Simple Guide"
33
author: "rajwanur"
44
date: "2025-09-04"
5-
categories: [git, tools, version-control]
5+
categories: [git, tools, gitignore]
66
toc: TRUE
77
toc-title: "Table of contents"
8-
toc-depth: 5
8+
toc-depth: 3
99
---
1010

11-
# Understanding gitignore: A Simple Guide
12-
13-
If you are working with Git but find yourself dealing with unnecessary files cluttering your repository, **.gitignore** is a tool that can help. Let's explore what it does in plain terms.
11+
If you are working with Git but find yourself dealing with unnecessary files cluttering your repository, `.gitignore` is a tool that can help. Let's explore what it does in plain terms.
1412

1513
## What is gitignore?
1614

17-
.gitignore is simply a text file that tells **Git** which files or folders to ignore in your project. It works like an instruction list for version control - when Git sees something mentioned in this file, it pretends that file doesn't exist and will not include it in tracking changes.
15+
`.gitignore` is simply a text file that tells **Git** which files or folders to ignore in your project. It works like an instruction list for version control - when Git sees something mentioned in this file, it pretends that file doesn't exist and will not include it in tracking changes.
1816

19-
Think of it as creating a "do not pack" list before the travel. .gitignore helps programmers avoid committing files they don't want to track. It also helps programmers exclude the files that don't need to be versioned.
17+
Think of it as creating a "do not pack" list before the travel. `.gitignore` helps programmers avoid committing files they don't want to track. It also helps programmers exclude the files that don't need to be versioned.
2018

2119
## The Problem It Solves
2220

23-
When working with code - especially languages like SAS, R, or Python - we often generate temporary files:
21+
When working with code - especially languages like `SAS`, `R`, or `Python` - we often generate temporary files:
2422

2523
- Log files showing execution results
2624
- Temporary output files
@@ -30,11 +28,11 @@ When working with code - especially languages like SAS, R, or Python - we often
3028

3129
These files can clutter the repository, making it harder to see actual code changes. They also unnecessarily increase repository size, which can slow down operations.
3230

33-
.gitignore solves this by automatically excluding these unwanted files from version control without someone having to manually specify each time.
31+
`.gitignore` solves this by automatically excluding these unwanted files from version control without someone having to manually specify each time.
3432

3533
## How It Works
3634

37-
The .gitignore file uses simple patterns to match filenames:
35+
The `.gitignore` file uses simple patterns to match filenames:
3836

3937
- `*.log` - ignores all files ending with .log
4038
- `temp/` - ignores any folder named temp
@@ -47,16 +45,16 @@ For complete syntax please refer to the [official documentation](https://git-scm
4745

4846
These rules are applied whenever Git checks for changes, so you only see relevant modifications.
4947

50-
## About Multiple .gitignore Files
48+
## About Multiple `.gitignore` Files
5149

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.
50+
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.
5351

5452
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.
5553

5654
```{mermaid}
5755
---
5856
config:
59-
layout: fixed
57+
layout: auto
6058
---
6159
flowchart LR
6260
A[🏠 my-r-project/] --> B[📄 .gitignore<br/>ROOT LEVEL]
@@ -97,9 +95,9 @@ flowchart LR
9795

9896
### Basic Setup
9997

100-
For most projects, create a .gitignore file in your project's root directory with patterns specific to your language or tools:
98+
For most projects, create a `.gitignore` file in your project's root directory with patterns specific to your language or tools:
10199

102-
```
100+
```bash
103101
# Ignore log files
104102
*.log
105103
*.tmp
@@ -118,15 +116,15 @@ For most projects, create a .gitignore file in your project's root directory wit
118116
Different programming languages often have different temporary files:
119117

120118
- For SAS programs:
121-
```
119+
```bash
122120
# To exclude SAS log, lst, and sas7bdat files
123121
*.log
124122
*.lst
125123
*.sas7bdat
126124
```
127125

128126
- For R projects:
129-
```
127+
```bash
130128
# To exclude R temporary files
131129
.RData
132130
.Rhistory
@@ -135,7 +133,7 @@ Different programming languages often have different temporary files:
135133
```
136134

137135
- For Python projects:
138-
```
136+
```bash
139137
__pycache__/
140138
*.pyc
141139
.env
@@ -147,40 +145,40 @@ Different programming languages often have different temporary files:
147145

148146
We can set up global ignore patterns that apply to all our repositories:
149147

150-
```
148+
```bash
151149
git config --global core.excludesfile ~/.gitignore_global
152150
```
153151

154-
Then add common patterns in .gitignore_global file located at ~/ (home directory) that should be ignored across all projects.
152+
Then add common patterns in `.gitignore_global` file located at `~/` (home directory) that should be ignored across all projects.
155153

156-
## Important Limitation
154+
## Important Note
157155

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.
156+
While `.gitignore` is powerful, it has an important feature: 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.
159157

160-
If such a file is already included and needs to be excluded, this need to explicitly remove it from tracking using:
161-
```
158+
If such a file is already included and needs to be excluded from version control, this need to explicitly remove it from tracking using:
159+
```bash
162160
git rm --cached filename
163161
```
164162

165163
This removes the file from version control but leaves it on the local filesystem.
166164

167165
## Best Practices
168166

169-
1. **Create early**: Add .gitignore at the beginning of a project
170-
2. **Commit it**: Make sure .gitignore itself is version controlled
167+
1. **Create early**: Add `.gitignore` at the beginning of a project
168+
2. **Commit it**: Make sure `.gitignore` itself is version controlled
171169
3. **Share with team**: Everyone working on a project should use the same rules
172170
4. **Review occasionally**: As your project evolves, update your ignore patterns
173171
5. **Exclude all/include some**: To avoid new file types from being tracked, exclude all and include what is expected
174172

175173
## Resources
176174

177-
- [.gitignore syntax](https://git-scm.com/docs/gitignore)
178-
- [Understanding .gitignore](https://www.atlassian.com/git/tutorials/saving-changes/gitignore)
179-
- [Automatically Generate gitignore Files](https://www.gitignore.io/)
175+
- [`.gitignore` syntax](https://git-scm.com/docs/gitignore)
176+
- [Understanding `.gitignore`](https://www.atlassian.com/git/tutorials/saving-changes/gitignore)
177+
- [Automatically Generate `.gitignore` Files](https://www.gitignore.io/)
180178

181179

182180
## Conclusion
183181

184-
.gitignore is a simple but powerful tool that helps maintain clean repositories by excluding unnecessary files. It's not magical - just practical configuration that saves time and reduces clutter in version control systems.
182+
`.gitignore` is a simple but powerful tool that helps maintain clean repositories by excluding unnecessary files. It's not magical - just practical configuration that saves time and reduces clutter in version control systems.
185183

186-
If you haven't used .gitignore before, give it a try on your next project. You'll likely find yourself wondering how you ever worked without it!
184+
If you haven't used `.gitignore` before, give it a try on your next project. You'll likely find yourself wondering how you ever worked without it!

0 commit comments

Comments
 (0)