Skip to content
BENIBIX Learn

.gitignore

Development🔀 Version ControlGit Basics

Also known as gitignore, .gitignore File, Git Ignore

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

Think of it like

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

Example

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

Why it matters

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

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 code

console
$ cat .gitignore
node_modules/
.env
Git now skips the folder of downloaded packages and the .env file.

Common mistake

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

Key takeaways

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

Learn it properly