.gitignore isn't ignoring itself

This question already has an answer here:

  • Ignore the .gitignore file itself

    19 answers

  • What is the difference between an annotated and unannotated tag?
  • Git false positives after Ubuntu upgrade
  • Transfer git repositories from GitLab to GitHub - can we, how to and pitfalls (if any)?
  • gradle - getWorkingBranch error on gradle-git
  • Move specific git commit from master to branch
  • git-svn workflow for merging using svn.pushmergeinfo
  • How can I rewrite python __version__ with git?
  • Pushing to git repository located on an RDP client
  • Is it possible to keep .gitignore files out of SVN?
  • Monolytics repo and multiple node_modules folder
  • How to copy local changes from one pc to another using git
  • Windows 7. Git public key configuration
  • 4 Solutions collect form web for “.gitignore isn't ignoring itself”

    As Carl Norum pointed out, files are not allowed to be tracked in order to be ignored. You will have to call

    git rm --cached .gitignore

    in order for it to actually be ignored.

    But what you are trying to do is a very bad idea. The .gitignore file is supposed to be tracked, so it’s ensured that the stuff listed in there is actually ignored on all client machines. If that’s not the case, another dev might add a file to the repo that you wanted to ignore, and you will get into trouble.

    Even running the command above might already cause trouble, as it will delete that file for every dev.

    If for some reason you want to ignore stuff only on your machine (and you are sure that’s a good idea), you need to add that to .git/info/exclude. That file has the same function as .gitignore, but is not supposed to be shared with the other devs.

    Your .gitignore file only ignores untracked files. Since you’re presumably tracking your .gitignore file, you will see changes to it in the output of git status.

    If you want to ignore something but you don’t want to check it in, add it to your global git ignore file instead of the one checked into the repository.

    Stop tracking the .gitignore file:

    How to stop tracking and ignore changes to a file in Git?

    git rm --cached .gitignore 

    Possibly because you already added the .gitignore file in the past.

    Note that git will not ignore a file that was already tracked before a
    rule was added to this file to ignore it. In such a case the file must
    be un-tracked, usually with git rm --cached filename

    From https://help.github.com/articles/ignoring-files

    Git Baby is a git and github fan, let's start git clone.