Ignore contents of folder with .gitignore


In some cases you might want to keep a folder, but ignore the contents. For example, say we have the following folder structure:

WWW/
    app/
    tmp/
        tmp-file-1.html
        tmp-file-2.html

to keep the “tmp” folder in the repo and keep it empty add the following .gitignore file inside the tmp folder:

# Ignore all files in this folder.
*
!.gitignore

So essentially the new structure should be:

WWW/
    app/
    tmp/
        .gitignore
        tmp-file-1.html
        tmp-file-2.html

If you still have issues after adding this file, sometimes you need to clear your .git cache


Leave a Reply