Create a Global .gitignore

By  on  

The .gitignore file is cherished by developers because it can keep repositories clean after build files and OS-generated files (like .DS_Store) clutter the structure of your repository. What I find is that I'm constantly adding the same files and directories (like node_modules) to every repository and I find it tedious. I was hoping there was a way to globally ignore those files and directories ... and I've found it.

You can create your global .gitignore with this magic:

# Declare the global .gitignore
git config --global core.excludesfile ~/.gitignore_global

# Create the .gitignore_global file
touch .gitignore_global

# Go into edit mode so you can add the unwanted file listing
vim .gitignore_global

The snippet above creates a .gitignore_global in your user directory which is respected throughout your user directory. Now you don't have to explicitly, repeatedly add the same files and directories to individual .gitignore files! Excellent!

This shouldn't be considered a great solution for collaborative repositories though -- someone else will inadvertently submit unwanted files and directories because the repo's own .gitignore doesn't contain the unwanted file listing. For your own purposes, however, a global .gitignore is aces!

Recent Features

  • By
    Being a Dev Dad

    I get asked loads of questions every day but I'm always surprised that they're rarely questions about code or even tech -- many of the questions I get are more about non-dev stuff like what my office is like, what software I use, and oftentimes...

  • By
    JavaScript Promise API

    While synchronous code is easier to follow and debug, async is generally better for performance and flexibility. Why "hold up the show" when you can trigger numerous requests at once and then handle them when each is ready?  Promises are becoming a big part of the JavaScript world...

Incredible Demos

  • By
    PHP IMDB Scraper

    It's been quite a while since I've written a PHP grabber and the itch finally got to me. This time the victim is the International Movie Database, otherwise known as IMDB. IMDB has info on every movie ever made (or so it seems). Their...

  • By
    MooTools TwitterGitter Plugin

    Everyone loves Twitter. Everyone loves MooTools. That's why everyone should love TwitterGitter, a MooTools plugin that retrieves a user's recent tweets and allows the user to format them however the user would like. TwitterGitter allows the user to choose the number of...


    Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!