Just a quick tip for those using Git and constantly keep on adding personalized settings to their project .gitignore: not everyone uses vim and have to worry about .swp files and not everyone uses a Mac and has Mac turds everywhere.

What every Git user should know is that there’s a way to set a global .gitignore file. According to the man page:

Each line in a gitignore file specifies a pattern. When deciding whether to ignore a path, git normally checks gitignore patterns from multiple sources, with the following order of precedence, from highest to lowest (within one level of precedence, the last matching pattern decides the outcome):

  • Patterns read from the command line for those commands that support them.

  • Patterns read from a .gitignore file in the same directory as the path, or in any parent directory, with patterns in the higher level files (up to the toplevel of the work tree) being overridden by those in lower level files down to the directory containing the file. These patterns match relative to the location of the .gitignore file. A project normally includes such .gitignore files in its repository, containing patterns for files generated as part of the project build.

  • Patterns read from $GIT_DIR/info/exclude.

  • Patterns read from the file specified by the configuration variable core.excludesfile.

GitHub’s help pages show how simple it is to set the global core.excludesfile setting:

Global .gitignore

A global .gitignore file can also be used by adding one to your global git config. For example, you might create the file ~/.gitignore_global and add some rules to it. To add this to your config, run git config --global core.excludesfile ~/.gitignore_global

To get you started, there’s an entire folder in GitHub’s .gitignore repository dedicated to global .gitignore entries where you can copy from.

Tagged with →  
Share →

Leave a Reply

Google+