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
    I’m an Impostor

    This is the hardest thing I've ever had to write, much less admit to myself.  I've written resignation letters from jobs I've loved, I've ended relationships, I've failed at a host of tasks, and let myself down in my life.  All of those feelings were very...

Incredible Demos

  • By
    Upload Photos to Flickr with PHP

    I have a bit of an obsession with uploading photos to different services thanks to Instagram. Instagram's iPhone app allows me to take photos and quickly filter them; once photo tinkering is complete, I can upload the photo to Instagram, Twitter, Facebook, and...

  • By
    CSS Tooltips

    We all know that you can make shapes with CSS and a single HTML element, as I've covered in my CSS Triangles and CSS Circles posts.  Triangles and circles are fairly simply though, so as CSS advances, we need to stretch the boundaries...

Discussion

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