Phil for Humanity Phil for Humanity
A Guide for the Survival of Humankind and Helping the World, Society, and Yourself.

Git's .gitignore File

Often in any build environment, such as a Git repository, you may propagate a lot of data files that you do not want to check (commit) into your local copy of your repository. For instance, these temporary files are typically not saved into any repository: build log files, compiled derived objects, built libraries, executables, auto-generated temp files, etc.

While these files usually just sit in your repository directory until they are cleaned up or overwritten in the next build, they may accidentally be committed into your repository. A good way to guarantee that files are prevented from entering your source control is by adding them into your ".gitignore" file. By creating a ".gitignore" file in the root directory of your repository, you can list what files to be ignored by git commands.

Here are some common examples of the syntax of a ".gitignore" file.

$ cat .gitignore
# Lines that start with # are comments that are ignored.
# The next line ignores build log files of the filename "compiler.log" anywhere in the repository.
# Alternatively, you can use wildcards for all log files, executables, object files, and editor temp files by using standardized filename extensions.
# Or else, you can ignore an entire directory like this:

Keep in mind, that the ".gitignore" file can be a local file or committed into the repository for all users (recommended).

by Phil for Humanity
on 11/05/2012

Related Articles
 » Perforce Opened
 » Git Status
 » Git Log and Cat-File