miscellaneous_tips:20_software_development:git_notes:using_a_global_gitignore_file

Using a Global 'gitignore' File

In many projects, a user's preferred editor or development environment (e.g. VS Code, Eclipse, kdevelop, …) creates some specific files or subdirectories inside the project directory, and these files shall not be commited to the git project.

A common way to avoid this is to add the file patterns for these files to the .gitignore file of the project.

However, this approach has at least 2 disadvantages:

  • The user has to add the same file pattern to the .gitignore file of each project.
  • If several users work on a project with different editors, the shared .gitignore file has to contain all file patterns for all build environments preferred by any of the maintainers.


A simple way to avoid this is to use of a global, personal gitignore file, where the user can add the ignore patterns that are used in any git project he's working with.

It's very easy to set this up. Just create a global gitignore file in your home directory, with your preferred name, e.g. ~/.gitignore-global, add all the patterns you personally want excluded in all projects you're working on, and run the following command:

git config --global core.excludesfile ~/.gitignore-global


This command only needs to be run once. If you later need to add more ignore patterns, just edit the file ~/.gitignore-global accordingly.

The ignore file may contain lines like these:

# This global git ignore file (~/.gitignore-global) can be used to
# specify ignore patterns that are common for all your git projects,
# e.g. workspace settings of the editor / IDE you're using, etc.
#
# Edit this file, and run once:
#
#   git config --global core.excludesfile ~/.gitignore-global
#

# mbgrcs / mkssi project files
**/*.pj
**/*.use

# kdevelop project files
**/*.kdev*
**/.kdev4/

# vs code project files
**/.vscode

Source:


Martin Burnicki martin.burnicki@burnicki.net, last updated 2021-07-29

  • miscellaneous_tips/20_software_development/git_notes/using_a_global_gitignore_file.txt
  • Zuletzt geändert: 2021-09-03 10:39
  • von martin