If you plan to study in Germany, you have to submit an application for a student visa to the respective German mission abroad before travelling. Citizens of the EU are exempted from this duty, as well as - under certain conditions according to the EU-mobility program - foreigners who already hold a temporary residence permit as a student issued by another EU-country, due to the EU-mobility program, please see the Implementation Status of the REST-Directive of the Federal Office for Migration and Refugees.
Documents have to be presented proving inter alia that the applicant has been accepted for studies by the university. The German mission abroad will then forward the visa application for an opinion to the foreigners authority in the town housing the University.
The German mission abroad can only issue the visa for entry once the foreigners authority has given its approval.
Details on the documents to be presented with your visa application are often available on the website of the competent German mission abroad or directly from the mission itself.the application form for a visa can be downloaded here.
German missions abroad: Countries A to Z