How do I .ignore files with Git GUI?

25,132

Solution 1

You need to make sure the file you are still seeing are not currently committed or staged.

If you remove them (git rm or git rm --cached), and then add them as private file, then they will be ignored.

Solution 2

Your file looks good. Just make sure you don't have any kind of whitespace at the beginning of each line, it took me 4 hours to find why my .gitignore wasn't working correctly; the reason was of course a cut'n'paste issue where I had a vertical line of spaces at the beginning of the file.

You should be careful with git commit -a before making sure that your .gitignore file really cleans out everything you don't want. Either mark each file (or use wildcards) with git add *.cpp *.h or - like I prefer - develop your .gitignore as you progress, and always check with git status before commiting.

If you want to double-check that your .gitignore really works, try

git ls-files --others -i --exclude-standard

This should list all the files that you are currently ignoring.

To clean out the files you've already added (probably using git add ., a mistake we all make in the beginning =]) you can do like @VonC said: either run

git rm <filename>

or

git rm --cached <filename>

Another option of cleaning out all the files you've unintentionally added is to totally clean your repository, and then re-add everything again. If you want to clear out everything in the staging area, you can run

git --rm cached .

But remember to not run git add . Until you've made sure that git status only lists the files you really want in the repository.

Another very useful thing with git is that it doesn't need paths to files when using wildcards. If you list your ignored files and see that you want to remove all *.suo and *.log files, just run

git rm --cached *.suo *.log

and git takes care of finding all the files in your repository that matches that signature, no matter where in the tree they are.

Solution 3

I tried multiple ways to get this to work and it was finally pretty simple:

You must commit the .gitignore first!

Also, if you use TortoiseGIT - GitEx Commit Tool, there is an option to edit ignored files.

Solution 4

You are locating it right. .gitignore should be at the same folder, where is .git folder located. File inside also looks correct. However, I dont have a comment line at the top..

Share:
25,132
Darkmage
Author by

Darkmage

Updated on July 09, 2022

Comments

  • Darkmage
    Darkmage almost 2 years

    I have created a .gitignore file in the folder with the .git folder, but I still get the files I'm trying to ignore when doing a rescan of the repository.

    This is the content of the file.

    # Ignored files
    *.suo 
    *.user 
    bin 
    obj 
    *.pdb 
    *.cache 
    *_svn 
    *.svn 
    *.suo 
    *.user 
    *.build-res 
    TestResults 
    _ReSharper*
    

    What am I doing wrong? where is the file suppose to be located?