How to Make Git Ignore a Folder

Two ways to stop Git from tracking a folder — depending on whether it’s already been committed or not.
Git
DevOps
Tutorial
Author

Abdullah Al Mahmud

Published

January 5, 2026

To make Git ignore a folder, you need to add it to your .gitignore file. The exact steps depend on whether Git is already tracking that folder.

Case 1: The Folder Has Not Been Tracked Yet

  1. Open or create a file named .gitignore in the root directory of your project.
  2. Add the folder name with a trailing forward slash (/) on a new line:
# Ignore a folder anywhere in the project
folder_name/

# Or, ignore a folder ONLY at the root level of your project
/folder_name/

Case 2: The Folder Is Already Tracked

If you previously committed the folder, simply adding it to .gitignore won’t stop Git from tracking it — you must clear it from Git’s index first.

  1. Open your terminal at the project root.
  2. Untrack the folder. The --cached flag ensures the folder stays safe on your hard drive and is only removed from Git’s tracking:
git rm -r --cached folder_name/
  1. Add folder_name/ to your .gitignore file.
  2. Commit the changes:
git add .gitignore
git commit -m "Stop tracking folder_name"