Git FAQ
Frequently asked questions around Git and Version Control.
Git FAQ featured image

How to Ignore Files in Git with .gitignore

In a hurry? Watch our brief 1-minute vertical video that summarizes the info below.

In almost any project, there are files and folders that you don't want to include in version control. These can be dependency folders like /node_modules, log files, or system-specific files like .DS_Store.

The .gitignore file is Git's way of letting you specify what to ignore!

Using a .gitignore File

To start ignoring files, you first need to create a file named .gitignore in the root directory of your project.

Inside this file, you can list the files and directories you want Git to ignore, with one pattern per line.

Here are some common examples:

# Ignore a specific file
my-secret-file.txt

# Ignore all files with a certain extension
*.log

# Ignore a whole directory
/node_modules

# You can also add exceptions with the "!" operator
# This ignores the /config directory, but NOT the keep_me.yml file inside it
/config/*
!/config/keep_me.yml

The Git Cheat Sheet

No need to remember all those commands and parameters: get our popular "Git Cheat Sheet" - for free!

Ignoring a File That is Already Tracked

If you've already committed a file by mistake, simply adding its path to .gitignore won't be enough. Git will continue to track it because it's already in the repository's index.

You first need to tell Git to stop tracking the file by using the git rm --cached command:

$ git rm --cached my-temp-file.txt

This command removes the file from Git's tracking but keeps the actual file in your local directory. After running this command, you can add the file's path to your .gitignore file, and Git will ignore it from now on.

Tip

Ignoring Files in Tower

In the Tower Git client, you can simply right-click any untracked file in the Working Copy list and choose "Ignore". Tower will then add the file to your ".gitignore" file for you.

Ignoring a file in Tower

You can also find templates for ".gitignore" files for almost any programming language by visiting the free .gitignore generator on the Tower website.

Learn More

About Us

As the makers of Tower, the best Git client for Mac and Windows, we help over 100,000 users in companies like Apple, Google, Amazon, Twitter, and Ebay get the most out of Git.

Just like with Tower, our mission with this platform is to help people become better professionals.

That's why we provide our guides, videos, and cheat sheets (about version control with Git and lots of other topics) for free.