From an earlier answer of mine
The Free City was the result of a strategic impasse over the fate of Krakow and its fortresses in the aftermath of the Napoleonic Wars. In the negotiations at the Congress of Vienna, Prussia, Austria, and Russia all desired control of the city of Krakow, both for its fortresses and strategic location. Control over Krakow could allow an army to invade either Western Galicia or southern Poland. The solution to this dilemma was to create a nominally independent micro-state, the Free City of Krakow. By neutralizing Krakow in this fashion, it allegedly helped to ease tensions between these three powers.
Austrian leaders were not entirely satisfied with this arrangement. Emperor Alexander I at Vienna posed as a patron of Polish nationalism and although there were elements of the emerging Polonophobia of the Russian state in 1815, the fear for Austria was that Russia could champion Polish irridentism throughout Galicia. Therefore Metternich had the duchies of Zator, Oświęcim, and Żywiec created as part of the German Confederation. It became imperative for Metternich to have the German confederation directly share a border with the Krakow microstate so that any Russian attempt to restore Poland would meet the forces of the Confederation. Austria could then present a threat to Krakow's independence as a threat to the German confederation, which Austria politically dominated in its first decades, and not as a strictly Austrian affair.
The increased Polonophobia of the statist state as well as the failed Polish revolt of 1830 rendered the fear of a Russian-controlled Polish nationalism moot. The free state entered into a limbo existence that was not long-lived. Metternich's solution was fortuitous in 1846-7 when Austria was able to use the duchies as a staging ground to invade and annex Krakow. With the overall strategic rationale for including the duchies now irrelevant, they left the German Confederation in 1850 and became a component of the Kingdom of Galicia and Lodomeria and the Free City became a Grand Duchy of Krakow and a part of Austrian Galicia.