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
    CSS Filters

    CSS filter support recently landed within WebKit nightlies. CSS filters provide a method for modifying the rendering of a basic DOM element, image, or video. CSS filters allow for blurring, warping, and modifying the color intensity of elements. Let's have...

  • By
    Convert XML to JSON with JavaScript

    If you follow me on Twitter, you know that I've been working on a super top secret mobile application using Appcelerator Titanium.  The experience has been great:  using JavaScript to create easy to write, easy to test, native mobile apps has been fun.  My...

Incredible Demos

  • By
    Image Manipulation with PHP and the GD Library

    Yeah, I'm a Photoshop wizard. I rock the selection tool. I crop like a farmer. I dominate the bucket tool. Hell, I even went as far as wielding the wizard wand selection tool once. ...OK I'm rubbish when it comes to Photoshop.

  • By
    MooTools Accordion: Mouseover Style

    Everyone loves the MooTools Accordion plugin but I get a lot of requests from readers asking me how to make each accordion item open when the user hovers over the item instead of making the user click. You have two options: hack the original plugin...

Discussion

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