Man page - git-ignore(1)
Packages contas this manual
- git-fork(1)
- git-count(1)
- git-get(1)
- git-changelog(1)
- git-gh-pages(1)
- git-mr(1)
- git-feature(1)
- git-browse(1)
- git-rename-remote(1)
- git-summary(1)
- git-commits-since(1)
- git-lock(1)
- git-ignore(1)
- git-clear-soft(1)
- git-unlock(1)
- git-touch(1)
- git-missing(1)
- git-authors(1)
- git-pull-request(1)
- git-repl(1)
- git-clear(1)
- git-guilt(1)
- git-reauthor(1)
- git-rename-file(1)
- git-delete-submodule(1)
- git-bulk(1)
- git-undo(1)
- git-delete-tag(1)
- git-root(1)
- git-show-unmerged-branches(1)
- git-archive-file(1)
- git-delete-squashed-branches(1)
- git-create-branch(1)
- git-show-tree(1)
- git-magic(1)
- git-rename-branch(1)
- git-merge-into(1)
- git-graft(1)
- git-coauthor(1)
- git-cp(1)
- git-rename-tag(1)
- git-browse-ci(1)
- git-extras(1)
- git-fresh-branch(1)
- git-rebase-patch(1)
- git-brv(1)
- git-force-clone(1)
- git-pr(1)
- git-effort(1)
- git-ignore-io(1)
- git-stamp(1)
- git-delete-merged-branches(1)
- git-info(1)
- git-alias(1)
- git-scp(1)
- git-setup(1)
- git-local-commits(1)
- git-paste(1)
- git-contrib(1)
- git-show-merged-branches(1)
- git-sync(1)
- git-reset-file(1)
- git-delta(1)
- git-obliterate(1)
- git-abort(1)
- git-psykorebase(1)
- git-merge-repo(1)
- git-squash(1)
- git-standup(1)
- git-delete-branch(1)
- git-locked(1)
- git-utimes(1)
- git-release(1)
- git-sed(1)
apt-get install git-extras
Manual
| GIT-IGNORE(1) | Git Extras | GIT-IGNORE(1) |
NAME
git-ignore - Add .gitignore patterns
SYNOPSIS
git-ignore [<context>] [<pattern> [<pattern>]...]
DESCRIPTION
Adds the given _pattern_s to a .gitignore file if it doesn't already exist.
OPTIONS
<context>
-l, --local
Sets the context to the .gitignore file in the current working directory. (default)
-g, --global
Sets the context to the global gitignore file for the current user.
-p, --private
Sets the context to the private exclude file for the repository (.git/info/exclude).
<pattern>
A space delimited list of patterns to append to the file in context.
PATTERN FORMAT
Pattern format as described in the git manual
- A blank line matches no files, so it can serve as a separator for readability. To append a blank line use empty quotes "".
- A line starting with # serves as a comment. For example, "# This is a comment"
- An optional prefix ! which negates the pattern; any matching file excluded by a previous pattern will become included again. If a negated pattern matches, this will override lower precedence patterns sources. To use an exclamation ! as command line argument it is best placed between single quotes ''. For example, '!src'
- If the pattern ends with a slash, it is removed for the purpose of the following description, but it would only find a match with a directory. In other words, foo/ will match a directory foo and paths underneath it, but will not match a regular file or a symbolic link foo (this is consistent with the way how pathspec works in general in git).
- If the pattern does not contain a slash /, git treats it as a shell glob pattern and checks for a match against the pathname relative to the location of the .gitignore file (relative to the top level of the work tree if not from a .gitignore file).
- Otherwise, git treats the pattern as a shell glob suitable for consumption by fnmatch(3) with the FNM_PATHNAME flag: wildcards in the pattern will not match a / in the pathname. For example, "Documentation/*.html" matches "Documentation/git.html" but not "Documentation/ppc/ppc.html" or "tools/perf/Documentation/perf.html".
- A leading slash matches the beginning of the pathname. For example, "/*.c" matches "cat-file.c" but not "mozilla-sha1/sha1.c".
EXAMPLES
All arguments are optional so calling git-ignore alone will display first the global then the local gitignore files:
-
$ git ignore Global gitignore: /home/alice/.gitignore # Numerous always-ignore extensions *.diff *.err *.orig *.rej *.swo *.swp *.vi *~ *.sass-cache # OS or Editor folders .DS_Store .Trashes ._* Thumbs.db --------------------------------- Local gitignore: .gitignore .cache .project .settings .tmproj nbproject
If you only want to see the global context use the --global argument (for local use --local):
-
$ git ignore Global gitignore: /home/alice/.gitignore .DS_Store .Trashes ._* Thumbs.db
To quickly append a new pattern to the default/local context simply:
-
$ git ignore *.log Adding pattern(s) to: .gitignore ... adding '*.log'
You can now configure any patterns without ever using an editor, with a context and pattern arguments: The resulting configuration is also returned for your convenience.
-
$ git ignore --local "" "# Temporary files" *.tmp "*.log" tmp/* "" "# Files I'd like to keep" '!work' "" Adding pattern(s) to: .gitignore ... adding '' ... adding '# Temporary files' ... adding 'index.tmp' ... adding '*.log' ... adding 'tmp/*' ... adding '' ... adding '# Files I'd like to keep' ... adding '!work' ... adding '' Local gitignore: .gitignore # Temporary files index.tmp *.log # Files I'd like to keep !work
AUTHOR
Written by Tj Holowaychuk <tj@vision-media.ca> and Tema Bolshakov <tweekane@gmail.com> and Nick Lombard <github@jigsoft.co.za>
REPORTING BUGS
<https://github.com/tj/git-extras/issues>
SEE ALSO
<https://github.com/tj/git-extras>
| October 2024 |