The siege of Gibraltar only lasted 24 hours after the German declaration of war. The German government had been concerned about Spain joining with the rest of the Axis yet combined with Franco saying that he needed to focus on rebuilding his country and the fact Spain was in ruins. The German government didn't think it was likely to come under attack and if it did they assumed it couldn't be held, anyway. So the actual amount of reinforcement done by the German high command was limited. While they still sent some additional ground troops plus a small fleet the town had little protection.
A Franco-British fleet assembled outside of Gibraltar as a war became imminent. On the 22nd May they were radioed to be told that the German high command had declared war on France and by extent Britain. The fleet opened fire on the fort and sent multiple salvos at the fort while the fleet inside was reluctant to engage a fleet which outnumbered them three to one. After 12 hours of shooting at the fort the Franco-British fleet had lost a single destroyer and two heavy cruisers as well as a battleship had endured limited damage due to counter- battery fire while most of the fort was in ruins. The Spanish on the border between Gibraltar and Spain then radioed to say war had been declared and that in 15 minutes they would be allowed to attack the town.
10 minutes later the Spanish forces attacked and took the town itself with relative ease since all the armed forces were hiding in the rock and the remaining Spanish forces were now faced with trying to scale the heights and attack the fort.
The first forces to go up struggled with heavy enemy fire but the fleet out at sea launched a few more rounds before the Germans could get back inside their bunkers causing much of the fort's defenders to be killed. As soon as the bombardment ended a second attack went up and this time although with losses but they managed to climb up the heights and went through the gaps in the fort. Eight hours later the fort was totally cleared of all remaining German troops and the Spanish flag was raised over the Rock for the first time in hundreds of years.
They then jumped onto transports of the Franco- British fleet and were ferried across the straits to Morocco to join up with the bulk of the army already assigned to fight there and to take German Morocco .