First off, I'm loving Git (fast/awesome/free/open-source distributed version control system). If you haven't already, check it out!
I'd like to briefly mention how to ignore certain files from version control, both by project and globally. I'd also like to confirm that it's very easy to add files to version control, which are normally globally ignored.
Git makes it simple to ignore certain files/directories/patterns from version control by creating a .gitignore file in your project root, and optionally in any sub-directory. Check out the gitignore docs page for more.
That said, I quickly found myself ignoring the same patterns for every repository. Fortunately, Git also makes it easy to globally ignore patterns. You just set a global config property of core.excludesfile to tell Git where to look for a global gitignore file. The following two commands take care of setting the property and creating a file with a few popular ignore patterns.
git config --global core.excludesfile ~/.gitignore
printf ".project\n*.iml\n.idea/\nWEB-INF/\n" >> ~/.gitignore
The above commands will work on both Linux and Mac. Windows users will likely want to locate a global .gitignore file in some common user settings directory. You can then create/edit the text file any way you'd like.
For me, on Ubuntu Linux, I end up with a /home/jkrug/.gitignore file that looks like this:
You can also manually edit your .gitignore file, of course, and add comments if you'd like:
# Eclipse project files
# IntelliJ IDEA project files
# Java WAR directories
Now here's the bonus: if you have one repository in which you'd like to add a file that is globally ignored to version control, you can do so. Simply use a standard add command with a -f flag, e.g.,
git add -f WEB-INF/web.xml
The global ignores are especially useful to me when I fork a project that may not have an ignore for my primary IDE's (IntelliJ IDEA) configuration files. And when I have a custom project in which I'd like to add one of those global ignores--no problem!
Happy versioned coding :)