From 9bbc7469b43c2f28291bee6207be7134d5429057 Mon Sep 17 00:00:00 2001 From: Rajwanur Rahman Date: Thu, 4 Sep 2025 03:12:45 +0600 Subject: [PATCH 1/4] Initial commit --- site/posts/understanding-gitignore/index.qmd | 138 +++++++++++++++++++ 1 file changed, 138 insertions(+) create mode 100644 site/posts/understanding-gitignore/index.qmd diff --git a/site/posts/understanding-gitignore/index.qmd b/site/posts/understanding-gitignore/index.qmd new file mode 100644 index 0000000..89f6999 --- /dev/null +++ b/site/posts/understanding-gitignore/index.qmd @@ -0,0 +1,138 @@ +--- +title: "Understanding gitignore: A Simple Guide" +author: "rajwanur" +date: "2025-09-04" +categories: [git, tools, version-control] +toc: TRUE +toc-title: "Table of contents" +toc-depth: 5 +--- + +# Understanding gitignore: A Simple Guide + +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. + +## What is gitignore? + +.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. + +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. + +## The Problem It Solves + +When working with code - especially languages like SAS, R, or Python - we often generate temporary files: + +- Log files showing execution results +- Temporary output files +- Large datasets created during processing +- Configuration files specific to the local machine +- Compiled binaries and dependencies + +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. + +![Cluttered vs Clean Repository](cluttered-vs-clean.png) + +.gitignore solves this by automatically excluding these unwanted files from version control without someone having to manually specify each time. + +## How It Works + +The .gitignore file uses simple patterns to match filenames: + +- `*.log` - ignores all files ending with .log +- `temp/` - ignores any folder named temp +- `/build/` - ignores a build folder in the root directory +- `*.tmp` - ignores all temporary files with extension `.tmp` +- `!*.sas` - **do not ignore** all files ending with .sas +- `# This is a comment` - Anything after a # is a comment and is ignored + +```{mermaid} +flowchart TD + A[File in Project] --> B{.gitignore Pattern Match?} + B -->|Yes| C[File Ignored] + B -->|No| D[File Tracked by Git] + C --> E[Clean Repository] + D --> F[Repository with Unwanted Files] +``` + +These rules are applied whenever Git checks for changes, so you only see relevant modifications. + +## Different Ways to Use gitignore + +### Basic Setup + +For most projects, create a .gitignore file in your project's root directory with patterns specific to your language or tools: + +``` +# Ignore log files +*.log +*.tmp + +# Ignore compiled output +/bin/ +/dist/ + +# Ignore IDE configuration files +.idea/ +.vscode/ +``` + +### Project-Specific Rules + +Different programming languages often have different temporary files: + +- For SAS programs: + ``` + # To exclude SAS log, lst, and sas7bdat files + *.log + *.lst + *.sas7bdat + ``` + +- For R projects: + ``` + # To exclude R temporary files + .RData + .Rhistory + .Rproj.user + *.Rproj + ``` + +- For Python projects: + ``` + __pycache__/ + *.pyc + .env + .pytest_cache + .venv/ + ``` + +### Global Ignore Patterns + +We can set up global ignore patterns that apply to all our repositories: + +``` +git config --global core.excludesfile ~/.gitignore_global +``` + +Then add common patterns in .gitignore_global file located at ~/ (home directory) that should be ignored across all projects. + +## Best Practices + +1. **Create early**: Add .gitignore at the beginning of a project +2. **Commit it**: Make sure .gitignore itself is version controlled +3. **Share with team**: Everyone working on a project should use the same rules +4. **Review occasionally**: As your project evolves, update your ignore patterns +5. **Exclude all/include some**: To avoid new file types from being tracked, exclude all and include what is expected + +## Resources + +- [.gitignore syntax](https://git-scm.com/docs/gitignore) +- [Understanding .gitignore](https://www.atlassian.com/git/tutorials/saving-changes/gitignore) +- [Automatically Generate gitignore Files](https://www.gitignore.io/) + + +## Conclusion + +.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. + +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! From 9288a7789e5a9d6f751da1707511f0ae4f0ffcc2 Mon Sep 17 00:00:00 2001 From: Rajwanur Rahman Date: Thu, 4 Sep 2025 04:17:45 +0600 Subject: [PATCH 2/4] Remove unnecessary image and flowchart --- site/posts/understanding-gitignore/index.qmd | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/site/posts/understanding-gitignore/index.qmd b/site/posts/understanding-gitignore/index.qmd index 89f6999..0739751 100644 --- a/site/posts/understanding-gitignore/index.qmd +++ b/site/posts/understanding-gitignore/index.qmd @@ -30,8 +30,6 @@ When working with code - especially languages like SAS, R, or Python - we often 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. -![Cluttered vs Clean Repository](cluttered-vs-clean.png) - .gitignore solves this by automatically excluding these unwanted files from version control without someone having to manually specify each time. ## How It Works @@ -45,14 +43,7 @@ The .gitignore file uses simple patterns to match filenames: - `!*.sas` - **do not ignore** all files ending with .sas - `# This is a comment` - Anything after a # is a comment and is ignored -```{mermaid} -flowchart TD - A[File in Project] --> B{.gitignore Pattern Match?} - B -->|Yes| C[File Ignored] - B -->|No| D[File Tracked by Git] - C --> E[Clean Repository] - D --> F[Repository with Unwanted Files] -``` +For complete syntax please refer to the [official documentation](https://git-scm.com/docs/gitignore). These rules are applied whenever Git checks for changes, so you only see relevant modifications. From ef1d1f820c369e6dc60bca98e4d3730b1142293c Mon Sep 17 00:00:00 2001 From: Rajwanur Rahman Date: Sat, 6 Sep 2025 03:32:38 +0600 Subject: [PATCH 3/4] Add section on multiple .gitignore files in a project and .gitignore limitation --- site/posts/understanding-gitignore/index.qmd | 57 ++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/site/posts/understanding-gitignore/index.qmd b/site/posts/understanding-gitignore/index.qmd index 0739751..db15b3c 100644 --- a/site/posts/understanding-gitignore/index.qmd +++ b/site/posts/understanding-gitignore/index.qmd @@ -47,6 +47,52 @@ For complete syntax please refer to the [official documentation](https://git-scm These rules are applied whenever Git checks for changes, so you only see relevant modifications. +## About Multiple .gitignore Files + +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. + +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. + +```{mermaid} +--- +config: + layout: fixed +--- +flowchart LR + A[🏠 my-r-project/] --> B[📄 .gitignore
ROOT LEVEL] + A --> C[📁 R/] + A --> D[📁 data/] + A --> G[📁 vignettes/] + A --> J[📁 docs/] + A --> N[📄 README.md] + + B --> B1[".Rproj.user/
*.Rproj
.Rhistory
.RData
.Ruserdata
docs/
Meta/
doc/
*.tar.gz"] + + C --> C1[📄 utils.R] + C --> C2[📄 main_functions.R] + C --> C3[📄 plot_functions.R] + + D --> D1[📄 .gitignore
DATA SPECIFIC] + D --> D2[📄 raw_data.csv] + D --> D3[📄 processed_data.rda] + D1 --> D1A["*.csv
*.xlsx
raw_*
temp_*
backup_*"] + + G --> G1[📄 introduction.Rmd] + G --> G2[📄 .gitignore
VIGNETTE SPECIFIC] + G2 --> G2A["*.html
*.pdf
*_cache/
*_files/
figure-html/"] + + + J --> J1[📄 .gitignore
DOCS SPECIFIC] + J --> J2[📁 _site/] + J --> J3[📄 pkgdown.yml] + J1 --> J1A["_site/
*.html
search.json
sitemap.xml"] + + style A fill:#e1f5fe + + classDef gitignoreFile fill:#ff9800,stroke:#e65100,stroke-width:2px,color:#fff + class B,D1,F3,G2,H2B,H3B,I2,J1,K2 gitignoreFile +``` + ## Different Ways to Use gitignore ### Basic Setup @@ -107,6 +153,17 @@ git config --global core.excludesfile ~/.gitignore_global Then add common patterns in .gitignore_global file located at ~/ (home directory) that should be ignored across all projects. +## Important Limitation + +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. + +If such a file is already included and needs to be excluded, this need to explicitly remove it from tracking using: +``` +git rm --cached filename +``` + +This removes the file from version control but leaves it on the local filesystem. + ## Best Practices 1. **Create early**: Add .gitignore at the beginning of a project From 18a31037bb78a31786ee3fc316a8ec537a52c01d Mon Sep 17 00:00:00 2001 From: Rajwanur Rahman Date: Thu, 18 Sep 2025 21:44:07 +0600 Subject: [PATCH 4/4] Mostly cosmatic changes in codeblocks. Renamed a section to Important Note from Important Limitation. --- site/posts/understanding-gitignore/index.qmd | 60 ++++++++++---------- 1 file changed, 29 insertions(+), 31 deletions(-) diff --git a/site/posts/understanding-gitignore/index.qmd b/site/posts/understanding-gitignore/index.qmd index db15b3c..8a82336 100644 --- a/site/posts/understanding-gitignore/index.qmd +++ b/site/posts/understanding-gitignore/index.qmd @@ -2,25 +2,23 @@ title: "Understanding gitignore: A Simple Guide" author: "rajwanur" date: "2025-09-04" -categories: [git, tools, version-control] +categories: [git, tools, gitignore] toc: TRUE toc-title: "Table of contents" -toc-depth: 5 +toc-depth: 3 --- -# Understanding gitignore: A Simple Guide - -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. +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. ## What is gitignore? -.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. +`.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. -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. +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. ## The Problem It Solves -When working with code - especially languages like SAS, R, or Python - we often generate temporary files: +When working with code - especially languages like `SAS`, `R`, or `Python` - we often generate temporary files: - Log files showing execution results - Temporary output files @@ -30,11 +28,11 @@ When working with code - especially languages like SAS, R, or Python - we often 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. -.gitignore solves this by automatically excluding these unwanted files from version control without someone having to manually specify each time. +`.gitignore` solves this by automatically excluding these unwanted files from version control without someone having to manually specify each time. ## How It Works -The .gitignore file uses simple patterns to match filenames: +The `.gitignore` file uses simple patterns to match filenames: - `*.log` - ignores all files ending with .log - `temp/` - ignores any folder named temp @@ -47,16 +45,16 @@ For complete syntax please refer to the [official documentation](https://git-scm These rules are applied whenever Git checks for changes, so you only see relevant modifications. -## About Multiple .gitignore Files +## About Multiple `.gitignore` Files -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. +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. 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. ```{mermaid} --- config: - layout: fixed + layout: auto --- flowchart LR A[🏠 my-r-project/] --> B[📄 .gitignore
ROOT LEVEL] @@ -97,9 +95,9 @@ flowchart LR ### Basic Setup -For most projects, create a .gitignore file in your project's root directory with patterns specific to your language or tools: +For most projects, create a `.gitignore` file in your project's root directory with patterns specific to your language or tools: -``` +```bash # Ignore log files *.log *.tmp @@ -118,7 +116,7 @@ For most projects, create a .gitignore file in your project's root directory wit Different programming languages often have different temporary files: - For SAS programs: - ``` + ```bash # To exclude SAS log, lst, and sas7bdat files *.log *.lst @@ -126,7 +124,7 @@ Different programming languages often have different temporary files: ``` - For R projects: - ``` + ```bash # To exclude R temporary files .RData .Rhistory @@ -135,7 +133,7 @@ Different programming languages often have different temporary files: ``` - For Python projects: - ``` + ```bash __pycache__/ *.pyc .env @@ -147,18 +145,18 @@ Different programming languages often have different temporary files: We can set up global ignore patterns that apply to all our repositories: -``` +```bash git config --global core.excludesfile ~/.gitignore_global ``` -Then add common patterns in .gitignore_global file located at ~/ (home directory) that should be ignored across all projects. +Then add common patterns in `.gitignore_global` file located at `~/` (home directory) that should be ignored across all projects. -## Important Limitation +## Important Note -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. +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. -If such a file is already included and needs to be excluded, this need to explicitly remove it from tracking using: -``` +If such a file is already included and needs to be excluded from version control, this need to explicitly remove it from tracking using: +```bash git rm --cached filename ``` @@ -166,21 +164,21 @@ This removes the file from version control but leaves it on the local filesystem ## Best Practices -1. **Create early**: Add .gitignore at the beginning of a project -2. **Commit it**: Make sure .gitignore itself is version controlled +1. **Create early**: Add `.gitignore` at the beginning of a project +2. **Commit it**: Make sure `.gitignore` itself is version controlled 3. **Share with team**: Everyone working on a project should use the same rules 4. **Review occasionally**: As your project evolves, update your ignore patterns 5. **Exclude all/include some**: To avoid new file types from being tracked, exclude all and include what is expected ## Resources -- [.gitignore syntax](https://git-scm.com/docs/gitignore) -- [Understanding .gitignore](https://www.atlassian.com/git/tutorials/saving-changes/gitignore) -- [Automatically Generate gitignore Files](https://www.gitignore.io/) +- [`.gitignore` syntax](https://git-scm.com/docs/gitignore) +- [Understanding `.gitignore`](https://www.atlassian.com/git/tutorials/saving-changes/gitignore) +- [Automatically Generate `.gitignore` Files](https://www.gitignore.io/) ## Conclusion -.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. +`.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. -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! +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!