16

My .gitignore file has the following entries. I am trying multiple things here as I can't seem to get my file ignored;

WinAppSetup/*.exe
/WinAppSetup/*.exe
WinAppSetup/setup.exe
**/WinAppSetup/setup.exe

When I run git status from git bash, I still see;

    modified:   WinAppSetup/setup.exe

What entry in my .gitignore will allow me to ignore this file?

After editing .gitignore, do I need to close and re-open git bash to have the .gitignore file re-read?

UPDATE

As per user2407038's comment, the issue was that the file already existed in the repository. I was able to remove the file locally, stage and then commit those changes and update my remote. A new build of the application then successfully ignored the file.

It seems I can also update my .gitignore file without having to close and re-open git bash too.

Mr Moose
  • 5,946
  • 7
  • 34
  • 69
  • 6
    If your file is shown as modified, so it is in the repository. `.gitignore` only works on files not yet in the repository (or index). Perhaps you want to delete this file from the repo? – user2407038 Jan 24 '18 at 03:08
  • Oh wow! I didn't even think about that. I'll bet that is what it is. I'll try and delete it and see if that sorts things out. – Mr Moose Jan 24 '18 at 03:12
  • @user2407038, add your comment as an answer and I'll mark it as correct. – Mr Moose Jan 24 '18 at 03:24
  • I wonder what is the answer to the title.. – Timo May 01 '22 at 19:35

1 Answers1

33

.gitignore won't ignore a file that's already in your repository. You have to first remove the file for your repository.

You can remove a file from the repository without deleting the actual file with git rm --cached.

git rm --cached WinAppSetup/setup.exe

In this sort of situation I usually have the new .gitignore entry and the removal of the ignored file from the repository in the same commit.

Schwern
  • 153,029
  • 25
  • 195
  • 336
  • 1
    I'm accepting this answer, as it seems to do what I need, but the suggestion provided by @user2407038 is what really helped me fix this specific issue. – Mr Moose Jan 24 '18 at 14:27