You can lose citizenship by taking up another (non-EU) one without having jumped through quite some hoops before, have another citizenship and fight in their army without previously asking for permission (there's a blanket exceptions for EU, NATO, EFTA and a couple of others), by giving it up, or being adopted by foreign parents. In all cases you won't lose it if it'd make you stateless.
On the flip side if you lost your German citizenship previously due to the Nazis you can get it back no questions asked, some but quite low bars exist for cases like a woman marrying a foreigner (until 1953 that meant she lost citizenship). You can also get citizenship pretty much instantly if you live in a territory that once was Germany, or in the ex soviet block, and still are considered to be ethnically German.
For the rest it's generally get a work permit, get permanent residence, stay here for eight years, that can be reduced to seven by completing an integration course, six if you're aceing integration, pass a written test, got sentenced to more than a misdemeanour, know enough German, swear allegience to the free and democratic basic order, and are willing to lose your old citizenship (exception: EU or Swiss citizens, also, hardship. E.g. Iran simply doesn't release people from their citizenship, the US demands exorbitant sums -- but Americans still might want to get rid of theirs to get rid of the IRS).