HR departments have a workaround though - instead of a bad reference, they will simply confirm that yes, you worked there. Nothing else.
When I was there that was how this was done. Basically you would always get a reference letter when ending employment. The reference letter's language always sounds good, as in not giving a bad reference. However, a reference letter that states things like "employee X delivered his tasks on time and to the satisfaction of work standards" basically means that he's a slacker that does mediocre work at best. It has to say something like "We are ultimately saddened for employee X leaving because he always delivered his work early and to the highest standard thinkable". These are bad made-up English language examples to show the difference in language but there's basically template language HR departments use for this.
https://www.arbeitszeugnis.de/presse/geheimcodeliste.pdf (German)
This shows that there's a conflict: law forbids to discriminate someone with a bad review of their capability, motivation or fitness. But people always seem to try to work around this prohibition. Like giving a friendly declaration that someone worked at a company if they weren't impressed and give an enthusiastic recommendation in the other case.
I didn't bother, but if my future plans had included being an employee at a big company in Germany I definitely would have done so.
That's the norm in most places, isn't it? He didn't steal anything, he wasn't sacked, he didn't punch-out the boss, and he didn't shit on the carpet.
Nobody wants to be sued for giving a decent reference.
My dad was a soldier; his retirement reference (age 45) said something like "He is an oustanding officer who will succeed at any enterprise he turns his hand to". That impressed me, until I learned that any officer retiring from the army will get a reference pretty-much the same.
Note that retiring from the army at age 45 is very common. If you get to 45 without getting promoted past colonel, you need a new career, because serious promotion happens when your CO gets killed in combat; and beyond about 45, they won't be sending you into combat.
I never knew in Germany one is expected to obtain actual proper reference letters from past employers. Good to know just in case.
Long time ago (15+ years ago) I had worked in Poland. Back then I did get a written reference from the company I worked for. I can't say if those letters are required these days in PL.
This works in the US as well.