2

I created a .gitignore to ignore an untracked file called tola.txt, now when i do git status now tola.txt is gone but .gitignore is coming under untracked files. I have temp moved an entry .gitignore inside .gitignore file, but that's just a hack I believe, how can i get rid of this .gitignore mess?

root>$ git status
# On branch master
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   tola.txt
root>$ vim .gitignore

added tola.txt in .gitignore, but now .gitignore has become the untracked

root>$ git status
# On branch master
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   .gitignore
tintin
  • 5,676
  • 15
  • 68
  • 97
  • 3
    If you don't add `.gitignore`, no one else will know that `tola.txt` should be ignored and they'll accidentally commit it. `.gitignore` should be tracked. – Robert Rouhani Feb 26 '12 at 09:35

1 Answers1

7

IF you want everyone who uses the repo ( clones ) to have the file ignored, you add the .gitignore to your repo ( as in git add .gitignore followed by a git commit )

If you don't want others to see it or you are just trying things out and don't want to see the .gitignore, you can the patterns you want to ignore to the $GIT_DIR/info/exclude file. That is, you can add the tola.txt line to .git/info/exclude file.

manojlds
  • 290,304
  • 63
  • 469
  • 417
  • +1. Git's local exclude-file is the easiest way forward. Another option is to add .gitignore to itself (or to .git/info/exclude).. – Barend Feb 26 '12 at 10:22
  • 1
    @BarendGarvelink - Yeah, but I don't like adding `.gitignore` to itself as that defeats the *intent* – manojlds Feb 26 '12 at 10:24
  • 1
    I agree with you. It'll also be surprising if someone else adds a .gitignore file at some point in the future. `.git/info/exclude` is the proper way for local ignores. – Barend Feb 26 '12 at 10:34
  • I have to create an empty file "exclude"? because I do not have initial one in this directory – Anna Leonenko Dec 15 '16 at 13:29