Welcome to the Wefugees Community and thank you for reaching out to us.
First of all, you are indeed in a complicated situation and I would highly recommend you to get support by a lawyer. Is your girlfiend a German citizen or does she hold a residence permit here? If your child's mother is German, the child will also get the German citizenship. This may open the opportunity for you to apply for a residence permit as father of a German child (§28 Residence law) in future - even if you are not getting married. However, you also need to prove that you actually take care of the child and considering your current situation, the application will not be an easy procedure. The same applies for the marriage: The registry office (Standesamt) will ask for many documents and also wants to make sure, that it is not a fake marriage (only done to secure residence). Please see a list of required documents for the marriage in our blog. On the other hand, I am also not sure if the involved authorities (registry office etc.) will report you to the immigration office/police.
Please also read especially mbeon-Bernd's explanations in this thread, in which a very similar situation was discussed.
As I mentioned already, without a lawyer (and even with support) it will be very difficult to legalize your stay in Germany. If you can not or don't want to consult a lawyer in the first place, you may also consider to seek support in a migration counselling office. They offer free of charge and confidential service and you don't need to be afraid of being reported. Let us know if you need help in finding one close to your current location.
I hope this helps and please don't hesitate to get back to us with any further questions.
All the best,