91

Possible Duplicate:
How to exclude file only from root folder in GIT

For a specific JavaScript project, I am using the TinyWeb HTTP Server for local testing (to work around a specific security limitation that applies to file URLs). That program requires I have an index.html file in the root directory, but I do not want to commit that file to my Git repository.

How can I stop Git from bugging me about this "untracked file" on every commit? I do want to commit all index.html files located in subdirectories.

Community
  • 1
  • 1
PleaseStand
  • 31,641
  • 6
  • 68
  • 95

1 Answers1

158

Add this to your .gitignore (in the root folder):

/index.html

The leading / makes git use an absolute path (relative to the current .gitignore location), whereas all other lines are just treated as some kind of wildcard.

poke
  • 369,085
  • 72
  • 557
  • 602
  • 2
    But how do I do this in a global gitignore file? (core.excludesfile)? – Greg Ennis Mar 27 '14 at 14:06
  • 2
    @GregEnnis It works just the same there. The global ignore file, as well as the repository’s `.git/info/exclude` file are both interpreted in the same way as a `.gitignore` in the root of the working directory. – poke Mar 27 '14 at 15:38
  • I have a /path/to/a/folder/.env and If I add that to the global ~/.gitignore, it does not ignore. – Elijah Lynn May 21 '18 at 22:45
  • @ElijahLynn See [Why doesn't Git ignore my specified file?](https://stackoverflow.com/a/3833675/216074) – poke May 21 '18 at 23:13
  • 1
    Ahh, I think this won't work, I am trying to ignore a file in a repo but in my top level ~/.gitignore, not the repo/.gitignore. – Elijah Lynn May 21 '18 at 23:36
  • @ElijahLynn You mean the .gitignore is outside of the repository? That will only work when that file is configured explicitly as the excludefile with Git. But then it will also take repository-relative paths. Please open a new separate question if you can’t make it work. – poke May 21 '18 at 23:39