thank you for sharing your question with us.
Basically said, you can marry anytime if you have all documents required. If your girlfriend is german, you'll have a right to get residence permission for germany (but I think you know that already).
If you already have an appointment for the marriage, you should inform the BAMF as soon as possible about this new development so they can refrain from deportation in your case.
Note: You should be prepared that german authorities might suspect that the marriage is only a fictitious marriage and start further investigation on this. In case you are suspected you should seek advice from a lawyer!
I hope my answers were useful for you and I'll be very pleased if you contact me again with further questions. I'm a member of the MBEON-staff and I‘ll be glad to guide you over a longer period of time. Mbeon is an online consultancy for migrants via the mbeon-app, which you can install on your smartphone for free. Download it via App Store or Google Play Store. You'll find me In the mbeon-app under my name „Euskirchen, Frau Schaefer“ and get confidential one-to-one advice in a safe virtual room where nobody can wiretap messages. Further information: www.mbeon.de