Every so often you need to make sure a directory is created when you checkout a git repository. For example, if it's the output directory for a process like grunt/gulp. Because Git tracks files and not directories it doesn't make this easy but there is a way around.

For example let's make a new repo with a directory we need to be created but don't want to include the files (emptyDir) and another folder that will contain version tracked files.

$ mkdir CheckingDirectoryInGit/
$ cd CheckingDirectoryInGit/
$ git init
Initialized empty Git repository in /blah/CheckingDirectoryInGit/.git/
$ mkdir emptyDir
$ mkdir fullDir
$ touch fullDir/item.txt

If we check git status we'll see that it's only going to add the directory with the file in it:

$ git status -u
On branch master

Initial commit

Untracked files:
  (use "git add <file>..." to include in what will be committed)

    fullDir/item.txt

nothing added to commit but untracked files present (use "git add" to track)

However we can create a .gitignore file that includes everything in that folder ('*') and then exclude the .gitignore file so it's included in the repo.

$ echo '*' > emptyDir/.gitignore
$ echo '!.gitignore' >> emptyDir/.gitignore

Note: You could also create a .gitignore file with those two lines but I though this was easier to read.

Now when we check git status we see that the .gitfile is included:
$ git status -u
On branch master

Initial commit

Untracked files:
  (use "git add <file>..." to include in what will be committed)

    emptyDir/.gitignore
    fullDir/item.txt

nothing added to commit but untracked files present (use "git add" to track)

And we can add another file and it won't be included:

$ touch emptyDir/style.css
$ git status -u
On branch master

Initial commit

Untracked files:
  (use "git add <file>..." to include in what will be committed)

    emptyDir/.gitignore
    fullDir/item.txt

nothing added to commit but untracked files present (use "git add" to track)