but it certainly did nothing against barbarians.
Hard to prove a negative, all the invasions or border skirmishes which were avoided due to the presence of the walls. Direct attacks against the great wall were almost never attempted, they were an effective deterrent and protection against nomadic people for millenia. At minimum, they required invaders to trek hundreds of kilometers around stretches of the walls, or divert to outlying regions of China in order to avoid direct fighting against entrenched Chinese defenses.
Qin Shi Huang used wall constructions to enclose areas of pasture land, cutting the Xiongnu off from territory and solidifying a northern border, which had been loosely defined. Cyrus could have learned a thing or two.
Large stretches of the wall were created by the Han along the Hexi corridor as a static defense against Xiongnu after the breakdown of the Heqin marriage alliance/tributary agreement with the Xiongnu. The Han's construction of the wall, in combination with military settlements (tuntian) along the trade route broke the economic base of the Xiongnu and the confederation dissipated as a result.
Of the post-Tang conquest dynasties that did succeed in invading and controlling China, beyond simple raids over the walls:
The Liao were established in the aftermath of the An Lushan and Huang Chao Rebellions, after military and economic setbacks had shattered the Tang into numerous warlord states. When the Khitan rose to power in Northern China, constructions hadn't been done on the walls for centuries and they were unmanned. And what did the Liao do?
They built new walls in present-day Hebei province.
The Jin were set up on invitation by the Song dynasty in a military alliance against the Liao. The Jurchen clans already held populations on both sides of the Liao-constructed walls before they rose up to overthrow them. Once in power, the Jin -- the barbarians --
renewed construction of the walls, as a way to deter the Mongols.
the Yuan dynasty was only set up after multiple attempts to conquer China over 3 generations. Genghis Khan never attacked the walls, and had his armies ride long distances to circumvent the walls. The Yuan dynasty never added to the construction of the walls, mostly seeing it as unnecessary since they controlled territory far beyond the extent of the walls.
When the Yuan Dynasty fell, the Ming re-started construction of the walls, and form most of the parts that tourists think of as the Great Wall today. These fortifications were extensive, and secured the Ming northern border for centuries. As I said, the only reason the Qing were able to enter China was because they were invited by Wu Sangui, a Ming general, who opened the gates for them and allied with the Manchus to defeat a rebel leader who had captured Beijing, Li Zicheng. By this point the Ming were bankrupt, and being torn apart by multiple rebel armies setting up their own dynasties. The Ming emperor had already committed suicide before the Manchus had set foot into China proper.
And what did the Qing do after they conquered China?
They built walls. Though these walls were actually pointed the other direction, and were designed to keep Chinese peasants from migrating into the Manchu's homeland. These walls aren't considered part of The Great Wall, but are instead referred to as the Willow Palisade.