Frequently asked questions around Git and Version Control.
How can I ignore files that have already been committed to the repo?
Git can only ignore files that are untracked - files that haven't been committed to the repository, yet. That's why, when you create a new repository, you should also create a .gitignore file with all the file patterns you want to ignore.
However, of course, not everything goes perfect... and files slip through that you later would like to see ignored.
The Git Cheat Sheet
No need to remember all those commands and parameters: get our popular "Git Cheat Sheet" - for free!
Preparing the Cleanup
Before cleaning up your repository, you should conduct two important preparations:
- Make sure your .gitignore file is up-to-date and contains all the correct patterns you want to ignore.
- Commit or stash any outstanding local changes you might have. Your working copy should be clean before you continue.
How to Ignore Files
Our free online book explains the general process of how to ignore files in great detail.
Cleaning Ignored Files
In three steps, you can clean up your repository and make sure your ignored items are indeed ignored:
# Remove the files from the index (not the actual files in the working copy) $ git rm -r --cached . # Add these removals to the Staging Area... $ git add . # ...and commit them! $ git commit -m "Clean up ignored files"
Ignoring Committed Files in Tower
In case you are using the Tower Git client, the app does the heavy lifting for you: when trying to ignore a file that is already tracked in Git, Tower will ask if you want to untrack it - so that the ignore rules can do their work.
- Check out the chapter Starting with an Unversioned Project in our free online book
- More frequently asked questions about Git & version control