Nov 26, 2014

Ignore files in Git

In Terminal, navigate to the location of your Git repository and  type
touch .gitignore
Check this collection of useful .gitignore templates
This file usually appears in the root of the repository, you can get the root directory using
git rev-parse --show-toplevel
However we can have this file in any sub folder.

To ignore files that was already tracked we need to remove them from the index, but  first of all we need to Commit pending changes to avoid unexpected behavior
git rm -r --cached .
-r Allow recursive removal when a leading directory name is given.
-q git rm normally outputs one line (in the form of an rm command) for each file removed. This option suppresses that output.

git add .
git commit -am “Remove ignored files”
-a Tell the command to automatically stage files that have been modified and deleted, but new files you have not told Git about are not affected

If you get the warning
warning: LF will be replaced by CRLF in <file>The file will have its original line endings in your working directory.
You can simply use
git config core.autocrlf false
In Unix systems the end of a line is represented with a line feed (LF). In windows a line is represented with a carriage return (CR) and a line feed (LF) thus (CRLF). It’s nothing to worry about.

References
http://git-scm.com/docs/git-commit
https://help.github.com/articles/ignoring-files/
https://github.com/github/gitignore
http://git-scm.com/docs/gitignore