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.

  • Upload from git format-patch to ReviewBoard fails on “file not found in the repository”
  • Is Git's auto-detection scripted or is it within some Git executable?
  • How to prevent Gitlab from creating extra merge commit on branch merge
  • 'Your branch is ahead of 'origin/master' by 1 commit' on explicit push
  • I need git-svn to act as a Subversion v1.5+ client
  • How can I tell Emacs my git branch has changed?
  • 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.

  • Git - deleted some files locally, how do I get them from a remote repository
  • Can't change git remote origin
  • How to use to make a file executable on Openshift server after pushing it via git
  • How to use Github to manage dotfiles?
  • Updating a local repository with changes from a Github repository
  • Push to remote on GitHub pointed to a new server IP instead
  • 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.