# .gitignore

> A file that tells Git what to leave out, like keys and build files.

**Field:** Software Development  
**Category:** Version Control  
**Also known as:** gitignore, .gitignore File, Git Ignore

## Think of it like

Think of it like a do not pack list for a trip. Anything on it stays behind.

## Definition

A .gitignore file lists files and folders that Git should not track. It sits in the top folder of a repository. Each line is a name or a pattern, like node_modules/ or *.log. Files that match are left out of git status and never get staged by mistake. It is the usual place to keep out secrets, build output and big downloaded folders.

## Example

Jack adds .env to his .gitignore. Now the file with his passwords can never be committed by accident.

## Example code

```console
$ cat .gitignore
node_modules/
.env
```

Git now skips the folder of downloaded packages and the .env file.

## Why it matters

It keeps passwords out of shared history. It also keeps the repo small and clean.

## Common mistake

Adding a file to .gitignore after it was committed. Git keeps tracking it until you remove it with git rm --cached.

## Three principles

- **A list of skips.** Names and patterns Git ignores.
- **Keep secrets out.** Passwords never reach the history.
- **Before, not after.** It cannot hide a file already tracked.

## Related terms

- [Repository](https://learn.benibix.com/term/development/repository)
- [Staging Area](https://learn.benibix.com/term/development/staging-area)
- [Git](https://learn.benibix.com/term/development/git)
- [Dependency](https://learn.benibix.com/term/development/dependency)
- [.dockerignore](https://learn.benibix.com/term/infrastructure/dockerignore)

## Taught in

- [Git Add and Commit](https://learn.benibix.com/learn/development-version-control/git-add-and-commit): Git and GitHub, 2/13

---

Source: https://learn.benibix.com/term/development/gitignore
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-17
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
