Hello @Adi - welcome to our community and thank you for your question!
You need to hand in your passport at Standesamt in order to marry. In addition you will probably need to provide your certificate of birth, a certificate of no impediment and other documents. The officials at Standesamt will give you a list of all the required documents once they got your passport.
Getting married in Germany might take a while (e.g. to gather all the needed documents etc.), but to me it sounds like you should have enough time to do so.
You won't get deported as long as you are still in your Ausbildung - even if you give them your passport. After you finished it, you will either start working which will result in a residence permit for 2 years or you get a Duldung for 6 months that you can use to find a job. In both cases you should have enough time to marry, especially since your Ausbildung is not over yet (which will give you extra time).
If you can afford it, it's always a good idea to consult a lawyer. S/he can get an in-depth overview of your case and advise you more precise than we are able to. Apart from that you can also get in touch with local counselling centers and ask for their advice.
Best regards,
Thorgen