3

I'm new to git. I can hide several files or folders by adding their names or extensions onto the .gitignore file.

However, other people might see what files/folders I have ignored. I don't know is there a way or setting to make "only you can see the .gitignore file" on Github without making the repository private.

Is there any way to hide .gitignore file from other people but myself (or repo collaborator) ?

Iqbal Basyar
  • 167
  • 1
  • 10
  • No, you can't do that. – Lasse V. Karlsen Feb 07 '20 at 07:52
  • Does this other answer/question work for you? It basically states to put the files you want to exclude in configuration files inside .git directory (.git/info/exclude) https://stackoverflow.com/questions/6117109/is-it-possible-to-have-a-custom-gitignore-read-only-access – Simone-Cu Feb 07 '20 at 07:55
  • That's the exact goal of `.gitignore` to be committed and, so, share pattern of files that must not be committed. If you want to keep some pattern personal (but why?), use `.git/info/exclude` for just one repository or https://stackoverflow.com/a/43745276/717372 for all your repositories. – Philippe Feb 07 '20 at 08:53

1 Answers1

5

You can use the .git/info/exclude file, which is local to your repository (see here).

It uses the same syntax as the .gitignore file.

See also this answer for more information on when/why to use it.

Simon Doppler
  • 1,918
  • 8
  • 26