2

I want to add a file named Credentials to .gitignore, so here's how I did, I added the following line to .gitignore file which is in app directory:

/src/main/java/my/package/name/utils/Credentials.java

But it still shows up in git status.

  • did you `git add .gitignore` and `git commit` ? – mkrufky Nov 22 '15 at 18:08
  • Did you push this file in the remote repo? – Gabriele Mariotti Nov 22 '15 at 18:09
  • @mkrufky Yes, I executed `git add .`. There's no need to commit to see an updated git status. Staging area should update after `git add` –  Nov 22 '15 at 18:11
  • @GabrieleMariotti no I didn't. –  Nov 22 '15 at 18:12
  • @mkrufky But the staging area will be empty after a commit. How do I verify in that case? –  Nov 22 '15 at 18:14
  • 1
    Possible duplicate of [Making git "forget" about a file that was tracked but is now in .gitignore](http://stackoverflow.com/questions/1274057/making-git-forget-about-a-file-that-was-tracked-but-is-now-in-gitignore) – Andrew C Nov 22 '15 at 18:50
  • @mkrufky _changes to .gitignore dont take effect until you commit them_ - that's wrong, changes to `.gitignore` take effect immediately. – 1615903 Nov 23 '15 at 10:03

1 Answers1

5

Quoting man gitignore :

A gitignore file specifies intentionally untracked files that Git should ignore. Files already tracked by Git are not affected

If the file that you're looking to have ignored by git is already a file being tracked, you'll have to git rm --cached it first.

For more info: https://git-scm.com/docs/gitignore

mkrufky
  • 3,268
  • 2
  • 17
  • 37