Search code examples
gitgitignore

How to add a file to the .gitignore configuration


I have a working project, but there is a file I accidentally pushed to the remote branch and I need to ignore it in the .gitignore.

This is the structure:

/project
  /app..
  | ...
  | ...
  /public
    | myFile.json

I added this entry on my .gitignore file:

...
/public/myFile.json
...

But it continues recognizing it as a outgoing file. What am I missing here?


Solution

  • You need to remove the file from git also as the old file is still tracked:

    git rm --cached public/myFile.json
    

    With the --cached the file will stay in your local copy.