How to ignore all files, but not sub-folders

I don’t want to push any files, but only all the folders in git.

I have tried the following in my .gitignore file, but it is not working:

  • Find the git branch or branches from commit id
  • Subversion and mixed-revisions: recipe for broken builds?
  • Git: Merge a Commit into a different Branch
  • How do I revert a pushed commit back to being unstaged?
  • Why after copying git repository to another dir I have modified files?
  • Close Jira issue via Git commit
  • # Ignore everything in this directory
    /*
    # Except for directories
    !/*/
    

    My folder structure is,

    /project/uploads
                     -->thumbnails
                     -->original
                     -->croped
    

    I need all the sub folders to go and neither files inside this “uploads” folder nor files in any other subfolders.

  • git-stash is moving my master branch
  • How I undo some changes in my workspace and get back to my last commit?
  • Git - Best practice: How to switch very often between branches and avoid multiples commits?
  • How Do I Push an Existing Eclipse Project Up to Bitbucket With EGIT?
  • EC2 can't SSH into github
  • How to squash my changes into a single result commit and pick into master branch?
  • 2 Solutions collect form web for “How to ignore all files, but not sub-folders”

    Git does only track files. If you ignore all of them git has nothing to track. A possible solution is to add a .gitignore to each directory. You can create all the subfolders, add a .gitignore to each of them.

    *
    !.gitignore
    

    This will then ignore all the files, but your gitignore files in the new directories.

    You are almost there:

    /*
    !*/
    

    There was just one / too much.
    With this you can ignore all files but not the (non-empty) directories.

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