Project setup with public and private "branches"

Completely new to Github, however programming since 40 years, and using git for about 2 years now. In very general terms I must admit first of all that I have still big troubles to get the “git logic” and “git language” into my head - much more than many programming languages (and also CVS and SVN…) that I already loaded into my head, so I would be very happy if somebody can explain in a not too much “git-ish” language or slang!

My question is about proper project setup with git and GitHub - which is related but not identical. So far I have it in a local git repository that is accessible only for myself, on an external computer with backup, so it should not get lost. It is all written in C++, with CMake as the build system and Qt for the GUI parts.

Now I have a “base” version of the software that I want to publish as Open Source, but then I also have an “extended” version that I can only sell for a license fee for some reasons. In order to get the code published I did some effort during the last months to make it two projects: the “base” that is in one git repository, and the “extended” as a separate second project that depends on “base” through some CMake constructs. The advantage is that I can now publish “base” freely while “extended” remains completely hidden. Still - I did not find time yet to really do the publication.

Instead I found a customer for whom I am writing another “custom extension” for the “base” version. So far I simply made it a “branch” of “base”, so I can switch between “master” and “customer”, and if there is something that should be shared I can “merge” between the branches - very handy and helpful!

However: Now the “base” repository is again not in a state that I can publish it - because it contains in a branch the “customer” code that I am not supposed to publish!

In other words: I am back in the same trouble - and it would again be very tedious to split the codes…

Ideally I would even merge the “extended” version back into the main repository and have then three “branches”: public “master”, and private “extended” and “customer”, but this is not possible! As far as I understand I have to either publish the entire repository (and expose also the “private branches”), or I have to do a huge effort to separate the open and closed parts of the code.

Now I was reading about some ways to deal also with such kind of problems with both Github and Gitlab, because you cannot only “branch” but also have some kind of “more separate branch” that still allows to also merge code from the one to the other - first of all from the public “master” to the private “children”.

So finally the question: Is this true - and if yes: What is the name of this technology, and where can I find some instructions to make it happen?

I would very much like to understand the procedure in advance, before I jump into reorganizing my entire code again (always very error prone!).

Many thanks in advance for any helpful answers!!