I am working on a maven project and I want to ignore the files generated and stored in the /target folder of my project (Evaluation) root folder.In the root of my git repository
I found that by deleting the repository, then having the .gitignore file in the folder when the repository is recreated the ignore file is respected.
In addition to the answers already provided above, also note that the .gitignore
file will not work if it is not in the root folder.
I had a project where .gitignore
was here /projectname/.gitignore
and therefore was not being read. So I moved it to /.gitignore
and all was well again.
I had a problem with bin folder being tracked (entire folder).
So here are the quick steps (more visual, as I'm more of a visual type of person):
I hope this helps someone.
Because there is the Sourcetree tag in the question I will answer you how to do this with Sourcetree, it's really simple.
As said before you first have to remove the file from tracking and then make Sourcetree to ignore the file.
This worked for me:
git update-index --assume-unchanged some.file
If the files have already been added or committed to your Git repository, you must first stop tracking them before they will be ignored by .gitIgnore.
To stop tracking files in SourceTree:
Right-click on files. Choose "Stop Tracking".
(this won't delete your files, it just stops tracking them)
To stop tracking files from Command-line:
git rm --cached example.txt