Bavaria gets the Rhineland at Vienna, Prussia regains it's part of the Polish partition
Best way is if Napoleon is more generous to Bavaria in the early 1800s, giving it the Kingdom of Westphalia and finding somewhere else for Brother Jerome. Maybe he thinks that a Germany divided
three ways is easier to control. Come 1813, the Bavarians show their gratitude by defecting to the Allies at the first opportunity, so at Vienna they are on the winning side and can't be dispossessed, but keep their ill-gotten gains or an equivalent. Austria will insist on getting Tyrol etc back, so Bavaria gets the Rhineland as compensation, and maybe part of Belgium as well.
I'm not so sure about the Polish partition. Trouble is, if 1812/13 has gone anything like OTL (which it must for Napoleon to be defeated) then Tsar Alexander is in possession of the Duchy of Warsaw. He seems to have been determined to keep it, and can't be dislodged except by war. My guess is that Prussia has to look elsewhere, maybe getting all of Saxony instead of half. Tough on the King of Saxony, but it's his own fault for not abandoning Napoleon sooner.
This leaves post-1815 Germany essentially run by a triumvirate of Habsburgs, Hohenzollerns and Wittelsbachs. No one else really counts. Things jog along until 1848, and then the fun really starts. Ludwig 1 probably abdicates as OTL, and is succeeded by his more intelligent son, Maximilian II. The following year, after the King of Prussia refuses the Imperial Crown, it is offered to Maximilian. He is inclined to accept, but in the face of an ultimatum from Russia and Prussia (Austria concurs but is still too distracted to do much) he backs down, while making it plain that he does so under duress - a bit like Charles Albert in Italy. Unlike CA, he firmly refuses to abdicate, and the powers don't push it. In the 1850s, he is ostentatiously more liberal then the other two German powers, and sends a contingent to the Crimea, along with Sardinia. This technically breaks the law of the German Confederation, but nobody dares make an issue of it. Max has too many allies at the moment.
His big chance comes in 1859. When Austria and France go to war, Max sends an ultimatum to Vienna, calling for drastic reforms of the Confederation, including an elected German Parliament. Franz Josef refuses, whereupon Bavaria denounces the Confederation and declares war. Austria is crushingly defeated - much more so than in OTL's 1859 - and with Franco-Bavarian forces at the gates of Vienna, Franz Josef abdicates. Austria (now ruled by Archduke Max as Regent for an infant Emperor Rudolf) makes a disastrous peace/ losing Venice as well as Lombardy. Bavaria puts in a claim to Tyrol and several other Austrian provinces, but waives it in return for Austria's formal renunciation of the German Confederation.
Meanwhile, the other powers have been dithering. Wilhelm, Prince Regent of Prussia, orders a general mobilisation, but this reveals so many problems and inefficiencies that he is unwilling to fight. The Tsar, whose Empire is still recovering from defeat in the Crimea, feels the same way. In the end, they look on while a new "West German Confederation" is formed, led by Bavaria, and with a directly elected Reichstag. Prussia is invited to join, but refuses.
An uneasy peace follows, but in 1863, The Schleswig-Holstein question erupts. Max II recognises the Duke of Augustenburg as Duke of S/H, and war breaks out between the WGC and Denmark. At this point, Prussia makes a fatal error, entering the war on the Danish side. The Prussians confidently expect Austria to join them against the Bavarian upstarts, but Archduke Max surprises everyone by allying with his namesake. He hasn't forgotten the latter's chivalrous behaviour in 1859, nor the way Prussia had, as he saw it, left Austria in the lurch. He joins the "German" side, and raises further eyebrows by giving command to the capable Arthur Gorgei, a Hungarian rebel whom he had amnestied four years ago. The combined Austro-German forces meet the Prussians near Erfurt and decisively defeat them. Their Danish allies, who arrived too late for the battle, hastily fall back and take up a defensive position in Schleswig.
Wilhelm I abdicates, and the new King, Friedrich III, sues for peace. The terms initially offered are severe, including restoration of the old Saxon Kingdom, but are quickly moderated when King Friedrich, who always favoured German unity, though wishing it to be under Prussia, indicates a willingness to join the Confederation. In the end, Prussia loses only Upper Silesia to Austria, and pays the Confederation's war expenses, but is otherwise left intact despite the protests of the old Saxon Royal House. Denmark, now isolated, is pushed back into Jutland annd forced to surrender S/H. A few weeks later, Maximilan II is proclaimed Emperoro of the Second German Reich.