Files showing in Solution Explorer but not in directory

I’ve got GitKraken set up with my GitHub account and UE4 project. I have different branches to help isolate work from other people.

However, just to test this out, I created ‘MyActor.cpp/.h’ in my Programming branch (staged, committed, and pushed). When I switch to my Development branch, I open VS first, compile, and open Unreal. The reason for this is so MyActor doesn’t show in the Content Browser. The files still show in the Solution Explorer in VS but the files are not physically in the Source file. I get the ‘unable to find file’ which is understandable, but I’m wondering why they’re still appearing in the solution explorer if the files don’t exist until I switch back to my programming branch. Is there a solution to stop VS from ‘loading’ files which don’t exist in the project? Or is it just the way VS works with solutions?

Sorry if this is the wrong section, wasn’t sure on where to post.