1

I want to hide my googleservices.json from git, thus I want to add it to the .gitignore file. My googleservices.json file is located inside android/app/googleservices.json

When I add this location to the .gitignore file, it still tracks it, What should I do?

phd
  • 82,685
  • 13
  • 120
  • 165
Delicia Fernandes
  • 582
  • 12
  • 19
  • Related, with many good answers: https://stackoverflow.com/questions/37358340/should-i-add-the-google-services-json-from-firebase-to-my-repository. It's about a *public* open source project, but the answers are useful. – Albert Vila Calvo Feb 02 '23 at 14:47

3 Answers3

3

If you already committed it once, you will have to explicitly remove it. git rm will do that.

However, if you already committed, it is forever visible in your repo's history. If you want to remove it from history, you will have to rebase the entire repo as if the commit that added the file never existed, or simply start over from scratch.

See also: How to permanently delete a file stored in GIT?

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
3

Just add this line to the gitignore file

*.json

If you want to permanently ignore changes to a file, then a safer way is to remove the information about the file from Git's index.

These steps don't delete the file from your system. They just tell Git to ignore future updates to the file.

Add the file in your .gitignore.

Run the following command after going into android/app/

git rm --cached googleservices.json

Commit the removal of the file and the updated .gitignore to your repo

Sunny
  • 407
  • 5
  • 15
2

you need to remove that file from git cache with git rm --cache googleservices.json