I have a paper written in LaTex and I use pdflatex to compile the paper directly to a PDF file. In addition, I have figures also in PDF format stored in a sub-folder of the main project. I don’t want Git to version my output PDF file, but I do want my PDF figures to be tracked.

In other words, I want to ignore all PDF files in my main project folder, but not PDF files in sub-folders.

I found that this is very simple and all I have to do is, in my .gitignore file, add a forward slash to the file type I want to ignore, but not in sub-directories. The .gitignore file is what I use in my project. Notice the forward slash in front of *.pdf

*.bak
*.log
*.sav
*.aux
*.bbl
*.blg
*.dvi
/*.pdf
._*
*.synctex.gz