Sunday, October 09, 2011

.gitignore by example

A git ignore is a file named ".gitignore" that gets placed in the top level directory of your git workspace.

It informs git to ignore files when adding and committing files.

# Exclude files with an extension
*.jar
*.o
*.a


# Do not exclude required.jar
!required.jar


# ignore the file TODO at the top level directory only
# thus /TODO will be ignored, but src/TODO will not be ignore.
/TODO


# To indicate a directory for ignoring it should end with a "/"


# This line ignores all directories and subdirectories named log/
log/


# This line only ignores the top level directory named build
/build/


# This ignores all files ending with txt inside doc/ directory, but not inside doc/example/
doc/*.txt

Important notes:
1. Files starting with / (slash) mean that you should start from the top level directory
2. The * (star) in doc/*.txt does not mean it will match any directories inside. It will only match top level files inside the doc directory ending with *.txt. Thus doc/example/test.txt will not be matched.

No comments: