If you create a file in your repository named .gitignore git will use its rules when looking at files to commit. Note that git will not ignore a file that was already tracked before a rule was added to this file to ignore it. In such a case the file must be un-tracked, usually with git rm –cached filename
This file can be committed into the repository, thus sharing the rule list with any other users that clone the repository.
Note that you can create a .gitignore in any subpath to have its rules applied at that path. Sometimes an empty .gitignore file is used as a placeholder for an empty path, for example to force git to generate a log/ path for your development environment to use.
To generate git ignore files, you can use the site: http://gitignore.io/ . you can make .gitignore files for any framework like grails, rails, cakephp et
Reference and taken from: