Okay, for the record, I don’t have experience publishing to GitHub Pages.
So I have trouble understanding the workflow: are you able to publish straight to Pages from your vault you otherwise sync with git? Are you just using one repository for both? (How do the Wikilinks, markdown links, paths, etc. work out? Obviously they do, right?)
But I think you are mixing things up here. You want to sync everything to GitHub (obviously) but you only want to publish only certain folders or notes – is that correct?
With .gitignore you filter what you’d be syncing with .git; I think it has no bearing on publish. But again, as I said, I don’t know about the Pages workflow (I’ve seen how CloudFlare, Netlify and Vercel are set up).
I use a Digital Garden template and (I must) use flags to decide what I want to publish, so I have a separate repository account for the vault (that I use for syncing) and another for what I want to publish, through the template.
So my suggestion is look around on other forums as well, how people filter what they want to publish to GH Pages, because there might be some flag (e.g. share: true, or something similar) that can be fed to GitHub Pages to not publish certain pages.
And with Properties in Obsidian, you can set up a Templater script or use some other plugin to mark markdown files in batch (a whole folder, at that) to exclude them from being published.
As I said, from what I’ve seen on this forum, not many people do what you do, so definitely look around on other forums as well.