1. git-ignore(1)
  2. Git Extras
  3. 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

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>

  1. April 2018
  2. git-ignore(1)