Tip Details Add a Related Tip

Rate as: Positive Negative

Getting git to ignore files already in repository

Like most other version control systems, git provides a way to ignore files in your project path through the use of the .gitignore file (see http://book.git-scm.com/4_ignoring_files.html for how this works).

The one problem with the .gitignore file is that it is only applied to files that are not already in your git repository. If you create your git project and then notice some files you want to leave out, adding them to the .gitignore file will do nothing. You may think that your .gitignore file is not working, I know I thought that when this happened to me!

So what are you to do if you want to ignore files that are already in the repository? The short answer is, you take them out. And since this is git, this turns out to be pretty easy to do...

If the files you want to remove are files (not folders), you can use this command to remove them from the repository while leaving them in place and untouched in your project path:

git rm --cached YOUR_FILE_NAME(S)

If the thing you are trying to ignore is a folder and you want to ignore all of the files under the folder, you need to add the -r flag to the command so it will recurse:

git rm -r --cached YOUR_FOLDER_NAME(S)

Once you do this, you can run the git status command and you will see that the files/folders you removed are now listed as being untracked.

If you then add these files/folders to the .gitignore file and run the git status command again, you'll see that the files/folders are now being ignored. Problem solved!
Rating: 100% positive, 2 total Votes
Categories: git version control
Added: on Oct 16, 2009 at 7:36 am
Added By: an anonymous user
Searches: file git ignore version control

Comments on this Tip

Add a Comment
There are no comments for this tip
Your Comment:
(how to format)
Rate This Tip:

Verify Humanity:
Sorry, we know it's annoying, but please enter the characters shown in the image to the left so that we know you're an actual person and not an evil spammer. Thanks.
       

Related Tips

So sad... this tip is all alone in the world

Related Categories