How to configure it to ignore files:
The ability to have git ignore files you don't wish it to track is very useful.
To ignore a file or set of files you supply a pattern. The pattern syntax for git is fairly simple, but powerful. It is applicable to all three of the different files I will mention bellow.
- A blank line ignores no files, it is generally used as a separator.
- Lines staring with # serve as comments.
- The ! prefix is optional and will negate the pattern. Any negated pattern that matches will override lower precedence patterns.
- Supports advanced expressions and wild cards
- Ex: The pattern: *.[oa] will ignore all files in the repository ending in .o or .a (object and archive files)
- If a pattern has a directory ending with a slash git will only match this directory and paths underneath it. This excludes regular files and symbolic links from the match.
- A leading slash will match all files in that path name.
- Ex: The pattern /*.c will match the file foo.c but not bar/awesome.c
Great Example from the gitignore(5) man page:
$ git status
[...]
# Untracked files:
[...]
# Documentation/foo.html
# Documentation/gitignore.html
# file.o
# lib.a
# src/internal.o
[...]
$ cat .git/info/exclude
# ignore objects and archives, anywhere in the tree.
*.[oa]
$ cat Documentation/.gitignore
# ignore generated html files,
*.html
# except foo.html which is maintained by hand
!foo.html
$ git status
[...]
# Untracked files:
[...]
# Documentation/foo.html
[...]
Generally there are three different ways to ignore untracked files.
1) Ignore for all users of the repository:
Add a file named .gitignore to the root of your working copy.
Edit .gitignore to match your preferences for which files should/shouldn't be ignored.
git add .gitignore
and commit when you're done.
2) Ignore for only your copy of the repository:
Add/Edit the file $GIT_DIR/info/exclude in your working copy, with your preferred patterns.
Ex: My working copy is ~/src/project1 so I would edit ~/src/project1/.git/info/exclude
You're done!
3) Ignore in all situations, on your system:
Global ignore patterns for your system can go in a file named what ever you wish.
Mine personally is called ~/.gitglobalignore
I can then let git know of this file by editing my ~/.gitconfig file with the following line:
core.excludesfile = ~/.gitglobalignore
You're done!
I find the gitignore man page to be the best resource for more information.