Saturday, 17 March 2012

howto: Ignore directories in Git on Windows

I recently created a local Git repository (see Steve Fenton's step-by-step guide) for a hobby project - it needs some rehactoring (sic) so I want a reliable fallback position. After I'd committed the source files I wanted to track, I was left with a lot of chaff:

I tried all the obvious tricks, in the obvious order: select the files, hit delete; select the files, right click, hunt for "exclude"; check each menu item; Google it; search StackOverflow; search the GitHub help. Nothing that said "This is how you exclude chaff files". So...

This is how you exclude chaff files

  • Create a file called ".gitignore" in your repository directory. This is incredibly easy in Windows, despite the "extension only" Unix style: Open Notepad, click Save As, navigate to your repository directory (not in the .git directory, but at the same level) and save the file as ".gitignore".
  • Edit the file to include the names or patterns of the files or directories you want Git to ignore. As an example, I used this list
  • Rescan the repository in the GitGui - this should now look much cleaner

  • Add .gitignore to the repository; stage, sign-off, commit etc
That's it, it's too easy!

1 comment:

  1. I've used this already to hide all my IDE files. Nice work!

    ReplyDelete