1. git-ignore(1)
  2. Git Extras
  3. git-ignore(1)

NAME

git-ignore - Modify or display .gitignore files

SYNOPSIS

git-ignore [<context>] [<action>] [--] [<pattern> [<pattern>]...]

DESCRIPTION

Modifies or shows .gitignore of selected context.

Possible actions are: addition of new patterns, removal of existing patterns from gitignore files, opening these files in text editor or simply displaying their contents in current terminal (for details see flags/usage).

Contexts are global (e.g. $HOME/.gitignore or $HOME/.local/.git/.gitignore), private (e.g. .../project/.git/info/exclude) and local (e.g. .../project/.gitignore)

Adding only happens for patterns that don't already exist in the file; removing patterns that are not present does not do anything; editing fails if the file is not yet present.

At most 1 context and 1 action matter for the program, the ones selected are the latest encountered in the flag list.

Default behavior:

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).

<action>

-e, --edit

Sets action to edit. This will open gitignore in a text editor (editor selection is the same as for git commit). If no context is provided local is assumed. Any pattern; provided in additional arguments is silently omitted.

-r, --remove

Sets action to remove. This will look for patterns in gitignore of selected context and remove if finds them. If no pattern is provided does nothing. All characters in pattern are treated literally, no interpretation of metacharacters is performed as would be, for example, for a regex pattern.

<pattern>

A space delimited list of patterns to append to the file in context.

--

End of options delimeter. Everything to the right of it is treated as positional arguments or more precisely a pattern.

-h, --help

Print a brief usage summary.

PATTERN FORMAT

Pattern format as described in the git manual

EXAMPLES

All arguments are optional so calling git-ignore alone will display global, local and private gitignore files in order:

$ 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
---------------------------------
Private gitignore: .git/info/exclude
notes.txt
test.sh
.env.local
config.json

If you only want to see the global context use the --global argument (for local use --local, for private use --private):

$ 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 (or use a shortcut to open file in editor when needed), 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 '*.tmp'
... adding '*.log'
... adding 'tmp/*'
... adding ''
... adding '# Files I'd like to keep'
... adding '!work'
... adding ''

Local gitignore: .gitignore

# Temporary files
*.tmp
*.log
tmp/*

# Files I'd like to keep
!work

Removing patterns works in a similar way. Select context and pass patterns to be removed from the gitignore file.

$ git ignore -l -r "*.log"
Removing patterns from local gitignore: .gitignore
... removing '*.log'

Local gitignore: .gitignore

# Temporary files
*.tmp
tmp/*

# Files I'd like to keep
!work

If you want to open gitignore in an editor and do changes manually pass -e flag:

$ git ignore -p -e

AUTHOR

Written by Tj Holowaychuk <tj@vision-media.ca> and Tema Bolshakov <tweekane@gmail.com> and Nick Lombard <github@jigsoft.co.za&gt and Kirill Dergachev <kdergachev1062@gmail.com>

REPORTING BUGS

<https://github.com/tj/git-extras/issues>

SEE ALSO

<https://github.com/tj/git-extras>

  1. June 2026
  2. git-ignore(1)