Skip to content

Instantly share code, notes, and snippets.

@edwardw
Created September 25, 2012 07:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edwardw/3780436 to your computer and use it in GitHub Desktop.
Save edwardw/3780436 to your computer and use it in GitHub Desktop.
Double negation in gitignore

Usually .gitignore is used to exempt certain files and directories from being reported by git status. The name .gitignore itself also suggests such usage. But when one does some experiments in sandbox directory, only a small portion of files are worth being version controlled. Instead of telling git what to exclude, it is more convenient to tell it what to include. Spotted such a .gitignore pattern today and it goes like this:

# Ignore all
*

# Except
.gitignore

# Include js directory
!js/
js/*
!js/*.js

It is quite a novelty for me. Double negation FTW!

As a sidenote, there are some links regarding .gitignore:

Ignoring files

gitignore templates

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment