you are viewing a single comment's thread
view the rest of the comments
[–] 2 points 3 weeks ago (2 children)

Does it prevent the initial .gitignore from being commited too?

For example, what if a file name had sensitive information. It's bad practice, but someone might want to ignore the file while also hiding the ignore rule itself.

/test/fake-person-first-last.json
/test/real-person-first-last.json

Someone might want to selectively omit the second file while keeping the first, but not show what they are hiding.

  • source
  • parent
  • hideshow 2 child comments
  • [–] 6 points 3 weeks ago

    .gitignore doesn’t prevent things from being committed. It just tells git to ignore files that aren’t already being tracked. And you can easily override that with -f. Putting .gitignore inside of .gitignore will ignore itself (if it’s not already tracked).

  • source
  • parent
  • [–] 4 points 3 weeks ago

    If you're an end user, not a build tool, you'd rather want to place that in .git/info/exclude inside the repo. It's effectively another gitignore file, which won't be committed.

    But if you do need something like this for a build tool, then yeah, you can create a file /test/.gitignore with these contents:

    real-person-first-last.json
    .gitignore
    

    Then running git add . just adds /test/fake-person-first-last.json.

    Both /test/.gitignore and /test/real-person-first-last.json would be ignored right away.

  • source
  • parent