The answer cover the two world wars in which both Italy and Germany participated in.
World War I : Italy versus Central Powers
Italy fought the Central powers in World War I, in an attempt to consolidate their northern borders. They defeated Austria-Hungary despite the efforts of the German Empire. Italy joined the Triple Entente on April 26, 1915, and declared war on Austria-Hungary on May 23, 1915.
World War II : When Allies Invaded, Italy Turned against Germany
King Victor Emmanuel, leader of post-Fascist Italy, declared war on Germany Oct. 13, 1943. The part of Italy that Victor Emmanuel controlled was only the part that the Allies had liberated by that date. But as Allied Forces moved up the boot of Italy, more and more of Italy's resources were utilized in the Allied war effort towards Italy's former partner in the Axis.
The Italian Royalists against the German Puppet State
The Italians of the "Kingdom of the South" were considered "co-belligerents" by the Allies. Thus not actually allies, and not part of the allied forces. They are often referred to as "Royalist troops". The first such troops were created on September 28, 1943, and saw action in the Cassino sector (Monte Lungo).
Existing simultaneously was the Italian Social Republic, created on September 18, 1943, fighting on the Axis side until the end. It only fielded about 60,000 frontline troops (then again the Kingdom of the South's peak strength was about 22,000 men on the Allied side). But Mussolini had large bodies of paramilitary fascist troops in an internal security role.
Italian History in World War II
Benito Mussolini was the dictator of Italy and he signed a pact with Hitler in 1939 to be their ally. The war started soon after that and Italy began to lose men and equipment. Then when the war reached Sicily, an island that belongs to Italy, and when the Allies began bombing Italy and especially Rome, the people rebelled against the Germans and Fascists. Italy had a king, King Victor Emmanuel II, who did not run the country.
On July 24, 1943, The Fascist Party held a meeting. After a 2-hour speech by Mussolini, his son-in-law, Ciano, made a motion to remove Mussolini from power. After 9 hours of debates, Mussolini demanded a roll-call vote and lost. The next day, Mussolini held a meeting with King Emmanuel, and the King simply asked Mussolini to step down. Mussolini had been physically sick and so he just agreed to it. Mussolini was placed under arrest and General Badoglio was placed in temporary charge of the country and restored order. There was very little revolt by the Fascists.
The Germans expected something was up. The Italian Government began secret negotiations with the Allies to switch sides. Many in the Allied command did not trust Italy and demanded unconditional surrender. There was talk of dropping US paratroopers into Rome so they could help the Badoglio government take control of the German troops. The Allied landing force departed for their attack on the Italian mainland at the Salerno beaches (on Sept. 9, 1943). Time ran out for Italy to make a decision. Italy announced they would surrender to the Allies.
The Germans initiated Operation ACHSE to disarm all the Italian soldiers in Italy and abroad. Many Italians were executed and 615,000 Italians were transported to German labor camps. Within a few weeks, German reinforcements crossed over the Alps into Italy and took control of the country. The Italian Government of General Badoglio declared war on German on October 13, 1943, thus becoming an Allied co-belligerent, though not an ally.
As the Allies advanced up from the "toe" of Italy, they took over more and more of the southern half of Italy. The ex-Italian soldiers were put into service with the Allies and used as translators and to carry supplies on mule trains up the steep mountains. Eventually, the Italians were armed by the British and these were the co-belligerent forces or sometimes called the "army of the South". They formed into 4 combat groups and were sent into combat towards the end of the war.
Benito Mussolini was still in charge of the Fascist elements loyal to him and he remained allied to the Germans. He really had no power and was a puppet government. He re-organized the combat troops under a new name: RSI - Italian Social Republic, consisting of the ENR and GNR. The ENR was organized into 4 divisions. The GNR was formed as a new Fascist militia to replace the Black Shirts (MSVN). They were the primary anti-partisan security force.
Italian soldiers essentially had 3 choices : 1) head north behind the front lines and fight with Mussolini and the Germans, 2) head south of the lines and fight for the co-belligerent forces, or 3) serve as a partisan fighter.