Best practice for maintaining / upgrading different branches of your app?

This might be a silly question, hoping someone has some insight.

So basically I have a series of similar apps that are out in the wild. They all sorta do the same thing, and are all branched off of a main structure, but have changes is UX and other things. Something like 40 varieties overall.

My question is this: is there a good way to structure it so that if I find, say, a bug in the main version, fixing it in the 40 other varieties is as simple as possible? Or if I wanted to add or modify core functionality in them all? Does anyone have any experience with this?