git ignore specific directories

I wanted to recently upload my dotnetnuke website on git, now my website has gigs of images which i don’t want to upload over git.

I was searching on GIT and came across .gitignore file which gets created during repository creation, GIT has a documentation about ignorning files/folders and it’s specific sub-folder, however it does not seems to work in my case.

Here’s my folder structure:

*******Updated*******

.gitignore
public_html/Portals/_default/
public_html/Portals/0/
public_html/Portals/1/
public_html/Portals/110/

Now i want to ignore all folders under Portals except Portals/_default.
I tried based on the specification from GIT:

Example to exclude everything except a specific directory foo/bar (note the /* - without the slash, the wildcard would also exclude everything within foo/bar):

    $ cat .gitignore
    # exclude everything except directory foo/bar
    /*
    !/foo
    /foo/*
    !/foo/bar

Below is what i tried:

!/Portals
/Portals/*
!/Portals/_default

But this does not seems to work at all.

Can anyone get me in right direction.

One Solution collect form web for “git ignore specific directories”

From the git documentation for gitignore:

Example to exclude everything except a specific directory foo/bar (note the /* – without the slash, the wildcard would also exclude everything within foo/bar):

$ cat .gitignore
# exclude everything except directory foo/bar
/*
!/foo
/foo/*

Tada!

Git Baby is a git and github fan, let's start git clone.