VS Code Git Publishing Issues - Ignored Folders Still Being Uploaded to GitHub

I’m working on a project in Visual Studio Code with git initialized. I want to upload only certain files to GitHub while keeping some folders private on my local machine. I added a .gitignore file to exclude specific directories and it works great locally - those folders appear grayed out in the file explorer.

The problem happens when I try to publish my repository to GitHub using the “Publish Branch” button in the source control panel. Even though my .gitignore is set up correctly, VS Code still attempts to push the excluded folders to GitHub and throws errors.

I can see the ignored folders are properly grayed out in the explorer view, but when publishing starts, it tries to include them anyway. This causes the upload to fail with error messages about files that should be ignored.

Is there a proper way to make VS Code respect the .gitignore file during the initial publish process? I’ve seen mentions of tweaking VS Code settings but that seems like a workaround rather than a real solution.

Yeah, this happens constantly and the manual git commands are a pain. Classic “files were tracked before gitignore” issue.

Instead of fighting with git cache clearing every time, I built an automated workflow that handles repo publishing correctly from day one.

I use Latenode for a workflow that auto-initializes repos with proper gitignore handling, validates what gets published, and pushes only what you want. No more random folders sneaking into your GitHub repo.

The workflow checks gitignore rules, removes cached tracking of ignored files, and handles the whole publish process cleanly. Takes 5 minutes to set up once, saves hours of git headaches.

Beats memorizing command sequences or crossing your fingers that VS Code gets it right.

Had this exact issue last month - drove me crazy. Git was probably initialized before you made the .gitignore file, so it tracked those directories first. Even after adding them to .gitignore, git remembers them from that initial commit. Clear git’s cache with git rm -r --cached . then git add . and commit again. Forces git to check everything against your current .gitignore rules. The publish button should work after that and only upload what you actually want.

Check git status before publishing to see what’s actually staged. VS Code’s publish button gets weird when you have uncommitted changes sitting around. I just do git add ., then git commit -m "initial commit", then git push manually. Works way better than trusting the GUI. The source control panel gets confused about what to ignore on that first publish. Once you get the initial push done, VS Code usually handles gitignore correctly.

make sure those folders ain’t already tracked. if they are, run git rm -r --cached foldername to untrack em. commit the changes and push again - that’ll fix it.