In the last year or so I’ve discovered the wonders of GIT for managing source code and we’ve now moved the majority of our live code base in to repositories at work.
However, as with most learning curves, you make some mistakes at first. One thing that’s been really bugging me is that I didn’t know about the ".gitignore" file when creating my first few repositories. This means that all the binary files were also initially added. As soon as I learnt about the ignore file I went back and added it. Problem is, the git ignore file only limits finding new files to add, if the file is already being tracked then the ignore file has no effect. Have tried to find solutions, but most of the stuff seems to refer to "filter-branch" which to be honest I don’t fully understand.
So, here’s my:
Super Simple Method of Removing Files/Folders that should be ignored
Example: you wanted to ignore the "bin" folder from your project.
Make sure you have the correct line in your git ignore: e.g.
(This will match any folder starting with the word "Bin" or "bin")
Move the file or folder that’s currently being tracked to somewhere
that it won’t get committed.
Either move it out of the folder completely (we’ll put it back later) or just rename it to something else that will get ignored e.g. renaming "bin" to "bin_" would work for me.
- Commit the changes (check it contains removes for each of the files you should be ignoring, perhaps the updated ".gitignore" file, but make sure it isn’t re-adding the files from your temporary directory or filename!)
- Now simply rename your files or folders back and now it won’t be appearing.
Perhaps there’s some kind of smarter way of doing this, but I just find this method really easy to understand! It certainly made my day when I finally got rid of these files!