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:

  • Can git filter out certain lines before commit?
  • Commit without changes
  • Can't push on a remote git branch in xcode
  • Remove Commit from Repository History
  • Revert to previous commit and ignore any uncommited changes in git
  • How can I change code within a commit to help find a bug?
  • # 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.

  • How can I completely remove/destroy commits from a git repository?
  • Keeping repositories in sync without being able to push and pull commits
  • Change Source Commit
  • How do I do a 'git blame' in NetBeans?
  • what is the meaning of setStartPoint in jgit when you move branch?
  • Display the most recent commit of each branch in git
  • 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.