0

Contents of my .gitignore file within my project directory:

bin/
.settings/
.classpath
.project
MyGuide.txt
.gitignore

What is showing up in my github project:

enter image description here

Is there a reason "MyGuide.txt" and the .gitignore files are still being displayed when I push to my remote repo?

  • 2
    did you happen to `git add` those files manually? or create and push them before you put the .gitignore in place? – radai May 08 '16 at 13:20
  • @radai I'm having a hard time recalling at the moment. Should a .gitignore be created before adding anything to the staging area? –  May 08 '16 at 13:24
  • 2
    ideally yes, it should be the 1st thing in. but you could always `git rm [file]` those files and next time you push they will be gone. also **you cant ignore the .gitignore itself** :-) – radai May 08 '16 at 13:26
  • Yeah, you should check .gitignore into your repo, so you shouldn't ignore it. – Sam Saint-Pettersen May 08 '16 at 13:41
  • @radai gotcha, thanks! And yeah, trying to go meta ;) –  May 08 '16 at 13:41
  • Possible duplicate of [Stop tracking and ignore changes to a file in Git](http://stackoverflow.com/questions/936249/stop-tracking-and-ignore-changes-to-a-file-in-git) – 1615903 May 09 '16 at 04:42
  • @radai _"you cant ignore the .gitignore itself"_ - actually you can, but you shouldn't. – 1615903 May 09 '16 at 04:44

1 Answers1

1

Looks like your file is already added to the git repo.

Once file is added (not untracked) adding it to .gitignore will not ignore it since its already in the repo so you have to remove it from the repository, commit the deletion of the file and then it will be ignored.

# Remove any file you have already commited and you wish to ignore
git rm -rf --cached .idea/*

# now add the ignored pattern to your .gitignore file
git add -A .

# commit and push the removal of the ignored files.
git commit -m "Removed idea files"
git push
CodeWizard
  • 128,036
  • 21
  • 144
  • 167