29

My GitHub Desktop app is trying to commit a bunch of files that are (supposedly) ignored.

GitHub Desktop Screenshot

As you can see, the entire .metadata folder is listed in my top-level .gitignore file. Still, there are loads of files from that folder that are being committed each time. Am I missing something about where the file needs to be placed?

EDIT: I should add, please do not just tell me to use the command line.

1615903
  • 32,635
  • 12
  • 70
  • 99
Derek
  • 799
  • 2
  • 8
  • 17
  • 7
    `.gitignore` is only used during "git add" commands when figuring out which files to add. If you've already added a file to the index, git will **always** track its contents, even if you later on add something to `.gitignore` that would add this kind of file. As such the only likely reason is that you've already added all those files to your git repository. – Lasse V. Karlsen Apr 12 '17 at 22:32
  • 4
    The correct way to handle these would be to clean your current working folder of all untracked files (`git clean -fdx`), then manually ask git to remove all files you longer want it to track (`git rm .metadata/*`), and then to commit that change. – Lasse V. Karlsen Apr 12 '17 at 22:34
  • 1
    I have the same issue. Somehow this is unexpected/ buggy behavior to my opinion. The files haven't been committed yet. The gitignore settings shall be considered dynamically and locally even if the .gitignore isn't pushed. I don't want to see this file in the list of changes if I have set a filter to ignore them. @1615903 this isn't a duplicate – Thierry Dalon Jul 11 '18 at 08:07
  • @ThierryDalon whether the .gitignore is pushed or not has nothing to do with this question. The bottom line is that gitignore only works for untracked files, and even OP has accepted the other question as duplicate. – 1615903 Jul 11 '18 at 08:11
  • Somehow my .gitignore was under a .gitignore folder (I think it comes from the template) and in this case the filter seems not to work, If I have the file .gitignore directy in the rep root, it works. – Thierry Dalon Jul 11 '18 at 08:22

1 Answers1

62

Most often the case is that if the files existed before they were added to the .gitignore file, they will not be ignored in any following commits or pushes.

My suggestions for you, since you don't want to use the command line, is cut the files/directories from your git directory, perform a commit, and then push. After the push finished, you can paste the offending files/directories back into the git repo and they should now be ignored.

Just in case you wanted to know, you can use the git bash git rm -r --cached some-directory and then perform a commit and push and you will have achieved the same result.

djreisch
  • 736
  • 6
  • 5
  • 6
    I'll try this out. To be clear, I don't mind using the command line, I just didn't want answers that were "Github desktop is bad I only use the command line blah blah blah". – Derek Apr 12 '17 at 23:10
  • Oh I totally understand. Good luck and I hope everything went well! – djreisch Apr 17 '17 at 15:55
  • 5
    I have the same issue. Somehow this is unexpected/ buggy behavior to my opinion. The files haven't been committed yet. The gitignore settings shall be considered dynamically and locally even if the .gitignore isn't pushed. I don't want to see this file in the list of changes if I have set a filter to ignore them. – Thierry Dalon Jul 11 '18 at 08:05
  • You can remove the repository from GitHub Desktop and move it to the trash, and then clone it again from GitHub. – Ryan Nov 11 '22 at 18:36