11

I searched around and found some tutorials explaining out to fix the problem, unfortunately they haven't worked.

Basically what's happening is I have files in the .gitignore that the github for mac program I'm using is trying to commit, despite them being ignored. I found some blogs and even other posts on stackoverflow saying that you can fix it with the command line, and giving explanations how. Unfortunately I have absolutely no experience with the command line and my attempts to follow their directions have all failed to solve the problem.

Is there a way to fix this problem without using the command line? and if not can someone tell me how to use the command line hack found here among other places:

git rm -r --cached .
git add .
git commit -m "fixing .gitignore"
bjb568
  • 11,089
  • 11
  • 50
  • 71
Nathan B
  • 157
  • 2
  • 12

1 Answers1

19

Are these files already tracked, and GitHub for Mac is trying to commit the modifications? .gitignore only prevents untracked files from being added/committed by git. Once a file has become tracked, .gitignore stops being consulted.

The "hack" you linked is really just asking git to delete all of the files in the repo, then re-adding it all back. This works because the .gitignore will be consulted when re-adding files (because it's consulted for any files not already in the index, and the git rm -r --cached . deleted the entire index).

Lily Ballard
  • 182,031
  • 33
  • 381
  • 347
  • Interesting, I'm still not sure how to use it though. I opened up the command line and copy and pasted `git rm -r --cached .` into it but it just said `fatal: pathspec '' did not match any files` and nothing changed. – Nathan B Jan 22 '13 at 03:48
  • What do you mean? I don't usually use github with the command line so I don't know how to run something in a working tree. I just cut and pasted the code into the command line, that's all. – Nathan B Jan 22 '13 at 04:58
  • 1
    @NathanB: By that I mean you were cd'd into the correct directory in your terminal? If you just launch Terminal.app then it will default to your home folder (just like Finder does). – Lily Ballard Jan 22 '13 at 05:14
  • Then no. I don't know how to run it in my working tree. How do you do that? – Nathan B Jan 22 '13 at 05:22
  • 3
    Type "cd " and then drag the folder that is your repository from the Finder into Terminal. Then hit return – Lily Ballard Jan 22 '13 at 05:24
  • Great Answer. It should be noted that some people might not have command line tools with the git command installed. If you are getting the 'git command not found' error when trying the command line option, check [here](http://www.hongkiat.com/blog/mountain-lion-git-fix/). Also be sure to check the OPs link for the full command line instructions. The cached command is not the only command needed. – Adam Johns Oct 29 '13 at 17:58
  • this doesn't seem to work for me. The ignore file seems to be completely ignored after doing that. – v3nt Nov 25 '15 at 13:02