Open source a project while keeping some things private

I have a private repository for a project I’ve been developing, and I’m trying to make it open source while keeping some of the code private. I’ve created a branch called “open_source” that has all of the code I would like to make open source. I realize I can’t make just this branch public, so is there a way I could copy it to a new repository that is public but still be able to pull updates from master of the original repository?

The reason the original repository has to stay private, is because it contains the source code for web tool hosted on AWS that we don’t want the public to have access to. We just want to make the code for the model being run by the web tool public. I hope that was all clear and thanks in advance for any help!

You could move the private code to a subfolder that is a Git submodule.

https://git-scm.com/book/en/v2/Git-Tools-Submodules

I’m not sure how GitHub handles submodules which are private repositories inside a public one, but I don’t really see a reason why it shouldn’t work (except that end users won’t be able to fetch the submodule, which is exactly what you want, I understand).