Here is the English translation of the relevant law according to the Gesetz-in-Internet webpages of the German Federal Ministry Of Justice.
Art. 10
Name
(1) The name of a person is governed by the law of the country of which the person is a national.
(2) At or subsequent to the conclusion of marriage, the spouses may, by a declaration given before the Registrar’s of Births, Marriages and Deaths Office choose the name they will use thereafter:
1. under the law of the country of which one of the spouses is a national, notwithstanding article 5 subarticle 1; or
2. under German law, if one of them has his habitual residence within the country.
If the declaration is made subsequent to the conclusion of the marriage, it needs to be publicly certified. As to the effect of the choice on the name of a child, § 1617 c of the Civil Code shall apply mutatis mutandis.
(3) The person having the parental authority may declare before the Registrar’s of Births, Marriages and Deaths Office, that the child shall obtain the family name
1. pursuant to the law of a country of which one of the parents is a national, without regard to article 5 subarticle 1; or
2. pursuant to German law, if one of the parents has his or her habitual residence within the country; or
3. pursuant to the law of a country of which a person confering the name is a national
Declarations made subsequent to the issuing of a birth certificate need to be publicly certified.