# Ignoring Things

### How to Ignore Things

## How to ignore things <a href="#firstheading" id="firstheading"></a>

What if we have files that we do not want Git to track for us, like backup files created by our editor or intermediate files created during data analysis? Let’s create a few dummy files:

```
mkdir results
touch a.dat b.dat c.dat results/a.out results/b.out
```

and see what Git says:

```
git status
```

Output

```
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       a.dat
#       b.dat
#       c.dat
#       results/
nothing added to commit but untracked files present (use "git add" to track)
```

Putting these files under version control would be a waste of disk space. What’s worse, having them all listed could distract us from changes that actually matter, so let’s tell Git to ignore them.

We do this by creating a file in the root directory of our project called .gitignore:

```
nano .gitignore
cat .gitignore
```

Output

```
*.dat
results/
```

These patterns tell Git to ignore any file whose name ends in .dat and everything in the results directory. (If any of these files were already being tracked, Git would continue to track them.)

Once we have created this file, the output of git status is much cleaner:

```
git status
```

Output

```
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       .gitignore
nothing added to commit but untracked files present (use "git add" to track)
```

The only thing Git notices now is the newly-created .gitignore file. You might think we wouldn’t want to track it, but everyone we’re sharing our repository with will probably want to ignore the same things that we’re ignoring. Let’s add and commit .gitignore:

```
git add .gitignore
git commit -m "Ignore data files and the results folder."
git status
```

Output

```
# On branch main
nothing to commit, working directory clean
```

As a bonus, using .gitignore helps us avoid accidentally adding files to the repository that we don’t want to track:

```
git add a.dat
```

Output

```
The following paths are ignored by one of your .gitignore files:
a.dat
Use -f if you really want to add them.
fatal: no files added
```

The following paths are ignored by one of your .gitignore files: a.dat Use -f if you really want to add them. fatal: no files added

```
git status --ignored
```

Output

```
# On branch main
# Ignored files:
#   (use "git add -f <file>..." to include in what will be committed)
#
#       a.dat
#       b.dat
#       c.dat
#       results/
nothing to commit, working directory clean
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://igb.mit.edu/mini-courses/version-control-with-git/ignoring-things.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
