DEV Community

Cover image for Dotfiles - Global Git Ignore
Michael Currin
Michael Currin

Posted on

Dotfiles - Global Git Ignore

Global git ignore content for ~/.gitignore - a user-wide git ignore file applied to all repos

See my full .gitignore file.

Configure git

First, configure your git config to be aware of a ~/gitignore file. You can name it anything you want.

[core]
    excludesfile = "~/.gitignore"
Enter fullscreen mode Exit fullscreen mode

Here's a quick to set that. Note that this won't add the double quotes but it will still expand correctly.

$ git config --global core.excludesfile '~/.gitignore'
Enter fullscreen mode Exit fullscreen mode

Create ignore file

Now setup the actual file. This follows the same format as a repo-specific file but it is not tied to a repo.

$ touch ~/.gitignore
Enter fullscreen mode Exit fullscreen mode

Then open it in your IDE. Use code instead touch above to open in VS Code.

The rest of this post covers the content you can add to that file.

Temporary metadata files

Sometimes files you don't want to version get left off of a repo's ignore file. For example it is only created using a certain OS or IDE and so it doesn't cross your mind to ignore it.

Here's a way to ignore files without having to add them to all your repos and this is especially useful if you are working on someone else's repo and you use a different OS or IDE to them.

# Linux folder attributes (Dolphin) and PyCharm metadata.
.idea/

.directory/

# macOS folder attributes. 
.DS_Store

# Vim swap file.
.swp
Enter fullscreen mode Exit fullscreen mode

The vim temporary file is a rare case - it is created when editing a file including when using vimdiff. It is easiest just to ignore it globally.

Ignore local notes

The content of my global git ignore file means I can have these in a repo without having to ignore them in a project ignore file.

TODO
_TODO

NOTES
_NOTES

# Avoid just 'TEST' as sometimes 'test' is a valid directory in some projects.
_TEST
_TESTS
Enter fullscreen mode Exit fullscreen mode

For example, I can text files in a directory (I don't both with .txt extension).

  • TODO
  • foo/TODO

Or add a directory of notes or work-in-progress.

  • _NOTES/foo.txt
  • _NOTES/bar.py

Top comments (0)