0Pricing
DevOps Bootcamp · Lesson

Understanding the .gitignore File

Learn how .gitignore keeps unwanted files out of your repository, with patterns, scope rules, and common pitfalls.

Understanding the .gitignore File is a free DevOps Bootcamp lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the DevOps Bootcamp learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Not Everything Belongs in Git

Build artifacts, logs, secrets, and dependency folders should never be committed. The .gitignore file tells Git exactly which files to skip.

What Is .gitignore?

A .gitignore is just a text file full of patterns. Any path that matches a pattern is kept out of staging and commits, keeping your repo clean.

Creating Your First .gitignore

Drop a .gitignore at your repo root, one pattern per line. The example below ignores dependencies, logs, and your env file.

# .gitignore
node_modules/
*.log
.env

Basic Pattern Rules

The basic patterns: *.log matches by extension, build/ matches a whole directory, and a plain name matches one exact file.

*.tmp
dist/
config.local.json

Anchoring with a Leading Slash

A leading slash anchors a pattern to the repo root, so /todo.txt ignores only the top-level file — not one with the same name deeper in the tree.

# only ignores /todo.txt at the root
/todo.txt
# ignores todo.txt anywhere
todo.txt

Negation with an Exclamation Mark

Prefix a pattern with ! to un-ignore something an earlier rule excluded — like ignoring all logs except one you want to keep.

# ignore all logs except the important one
*.log
!important.log

Wildcards: Star and Double-Star

For wildcards: a single * matches anything but a slash, while ** matches across directories at any depth.

# any file in any logs directory at any depth
**/logs/*.log
# any .cache file in this dir or below
**/*.cache

Comments and Blank Lines

Lines starting with # are comments and blank lines are skipped — use both to keep your .gitignore organized and readable.

# Dependencies
node_modules/

# Environment
.env

Already-Tracked Files Trap

Big gotcha: .gitignore only affects untracked files. If a file is already tracked, the rule does nothing until you untrack it with git rm --cached.

git rm --cached secret.txt
# now the ignore rule takes effect for future commits

Checking Why a File Is Ignored

Not sure why a path is ignored? git check-ignore -v tells you exactly which rule and line matched it.

git check-ignore -v build/app.js
# .gitignore:2:build/    build/app.js

Global Ignore

For personal clutter (editor configs, OS junk) that should never hit any repo, set a global ignore instead of polluting project files.

git config --global core.excludesFile ~/.gitignore_global

Quick Check

Test your .gitignore knowledge.

Recap

You mastered .gitignore: patterns, wildcards (*, **), anchoring (/), and negation (!). Remember it only touches untracked files — debug with git check-ignore.

Frequently asked questions

Is the “Understanding the .gitignore File” lesson free?

Yes — the full text of “Understanding the .gitignore File” is free to read here on the web, and the DevOps Bootcamp course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the DevOps Bootcamp course, upgrade to CoddyKit PRO.

What will I learn in “Understanding the .gitignore File”?

Learn how .gitignore keeps unwanted files out of your repository, with patterns, scope rules, and common pitfalls. You practise DevOps Bootcamp with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start DevOps Bootcamp?

No prior experience is required. DevOps Bootcamp on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Understanding the .gitignore File” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this DevOps Bootcamp lesson?

Yes. Every DevOps Bootcamp lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Introduction to Version Control
  2. Installing Git & Configuration
  3. Creating Your First Repository
  4. Understanding the .gitignore File
← Back to DevOps Bootcamp