CARVIEW |
Guides: Ignore for Git
To set certain files or patterns to be ignored by Git, you must either modify the $GIT_DIR/info/exclude file or create a file called .gitignore
in your project’s root directory. The former is not shared between repositories (so you can set ignores for your specific environment), while the .gitignore
is usually checked into Git and distributed along with everything else.
By default $GIT_DIR/info/exclude looks like this:
# git-ls-files --others --exclude-from=.git/info/exclude
# Lines that start with '#' are comments.
# For a project mostly in C, the following would be a good set of
# exclude patterns (uncomment them if you want to use them):
# *.[oa]
# *~
Both files use the same format for patterns and names.
To exclude specific file types, you can add to the bottom:
*.log # Will exclude all .log files
To exclude all files in a specified path:
path/to/ignore/files/* # The path starts at the $GIT_DIR and not '/'
You can also explicitly exclude certain files from being ignored by prepending a pattern with !
. Let’s say you want to ignore all files starting with a dot, but you don’t want Git to ignore the .gitignore
file:
.* # Ignore all dotfiles...
!.gitignore # except for .gitignore
To get more info on this topic, type man gitignore
on the command line to call up the manpage.