git ignore directory except for specified

I want to ignore entire public_html/ directory except one file inside

I give .gitignore as below:

  • Gitflow with multiple master branches
  • Push full copy of my git repo to my remote
  • How do I search git history for a disappeared line?
  • What does it mean when git pull causes a conflict but git pull --rebase doesn't?
  • Jenkins Git plugin included regions not working
  • Is there a menu like interactive commit for SVN like Git has with --interactive?
  • public_html/*

    However, when I run git status , I can not find config.php has been included.

  • Missing git file hooks/post-receive.sample
  • Removing all files from a just initialized git repo staging area
  • Git pull not pulling the latest revision
  • git push heroku hangs
  • Create an SVN branch from an existing Git branch
  • Two branches made changes to the same file. How to commit the changes of the file made in one branch and push to github master branch?
  • 2 Solutions collect form web for “git ignore directory except for specified”

    First commit / add public_html/config/config.php and then add public_html to the gitignore.

    Change .gitignore to


    And force adding config.php into index.

    git add -f public_html/config/config.php
    Git Baby is a git and github fan, let's start git clone.