The City Watch is a law-enforcement institution charged with acting as the policemen of King's Landing. They are informally known as "Gold Cloaks" due to the gold-colored cloaks their members wear as part of their uniform.
The City Watch of King's Landing is a strong, formally-trained and well-equipped force of guardsmen under the direct authority of the King on the Iron Throne. Their salary is paid by the kingdom as a whole and unlike many of the kingdom's other institutions they do not swear fealty to any lord other than the king.
The City Watch is supposed to double as a defense force in the event that the city is attacked, though prior to the War of the Five Kings a major attack on King's Landing hadn't occurred in generations (the Sack of King's Landing by House Lannister during Robert's Rebellion occurred after their army had already been let inside the gates, and was more of a massacre than a battle). The City Watch are not really true soldiers, as was evidenced by their lack of discipline during the Battle of the Blackwater, when many panicked when the tide of the battle turned dire.
The City Watch promotes by merit, one of the few institutions in Westeros not to recognize the status of birth. Its previous leader was Commander Janos Slynt, a butcher's son who rose through the ranks. Slynt was dismissed by Tyrion Lannister and replaced as Commander of the City Watch by Bronn, a lowborn sellsword in Tyrion's service. After Tywin Lannister assumes his duties as Hand of the King, he dismisses Bronn from command of the Watch.
The leader of the City Watch is referred to as "Lord Commander" when of noble birth, but simply as "Commander" when not. Janos Slynt was merely a "Commander" due to his lack of noble birth. Following Lord Stark's arrest, Janos was named the new Lord of Harrenhal and elevated to the nobility by King Joffrey as a reward for his loyalty. After this point he was referred to as "Lord Commander" Bronn was referred to simply as "Commander", as he was not of noble birth. Nonetheless, there is no functional difference, other than manner of address, if the leader is noble born or not.
Hand of the King Eddard Stark attempts to secure the loyalty of Janos Slynt and the City Watch, through Master of Coin Petyr Baelish, in his attempt to remove Joffrey Baratheon and his mother Cersei Lannister from power. Reluctantly, Stark agrees with Littlefinger's point that they'll need to bribe Slynt to make sure he's on their side. Unfortunately for Ned Stark, Janos Slynt had already been bought by the Lannisters. When Stark and his guards attempted to seize custody of Joffrey in the throne room, the City Watch under Slynt betrayed them, proceeding to slaughter all of Stark's guards in the castle and taking Stark prisoner.
King Joffrey (apparently without Cersei's knowledge), orders Janos Slynt and the City Watch to massacre all of Robert Baratheon's bastard children, even babies. Hand of the King Tyrion Lannister is disgusted with Janos Slynt as a baby-killer, combined with the fact that he betrayed the previous Hand, Eddard Stark, so Tyrion doesn't feel safe having him around. Tyrion has Janos stripped of his position, and exiled to the Wall to join the Night's Watch. He replaces Slynt as Commander of the City Watch with Bronn.
Even Varys later remarks to Tyrion that Bronn is actually performing very effectively as Commander of the City Watch. Bronn was able to restore order following the Riot of King's Landing, and even managed to make a significant drop in theft during the lead-up to the Battle of the Blackwater. Bronn explained that he simply had the City Watch arrest all of the known thieves and hold them indefinitely, fearing the mischief they'd get up to if they faced a prolonged siege. Varys agreed that desperate times called for drastic measures.
A pair of gold cloaks accompany Ser Jaime Lannister to the dungeons to escort Tyrion Lannister to the throne room to be judged for the murder of King Joffrey. Per Tywin Lannister's orders, the gold cloaks put Tyrion in shackles.
In the books
In the A Song of Ice and Fire novels, the Gold Cloaks are a force of some two thousand men, relatively well-equipped. While they promote by merit, they are not incorruptible and some Watchmen have a reputation for taking bribes to look the other way, though Ser Jacelyn Bywater is noted as one of the more honorable members of the City Watch. They are expected to help defend the city if it were to ever come under attack. Oldtown, the second-largest city in Westeros, also has a City Watch. Lannisport's City Watch is better paid and thus can afford to train its members to higher standards than King's Landing's City Watch. It is unknown if the other two cities in Westeros (Gulltown and White Harbor), or some of the larger towns, have comparable police forces.
While the City Watch existed since the early years of King's Landing, for many decades it was poorly organized, poorly armed, and irregularly outfitted in odds and rags. The true founder of the modern City Watch was Daemon Targaryen, younger son of King Viserys I. After King Jaehaerys I died in 101 AL, Viserys ascended the throne, while Daemon set about to reorganize the City Watch into a more professional and well-trained organization. Daemon outfitted each member of the City Watch with a dirk, short sword, and cudgel, and armored them in black ringmail (with breastplates for the officers). Daemon also outfitted each of them with long golden cloaks, which they could wear with pride to impress petty criminals, and ever since they were popularly known as the "Gold Cloaks". Daemon eagerly led the reorganized City Watch in cleaning up crime in the alleys of the capital city. Nearly three decades later, during the civil war known as the Dance of the Dragons, Daemon fought for his wife Rhaenyra Targaryen's "Black" faction, against the "Green" faction which supported her half-brother Aegon II, and which controlled King's Landing. When Aegon II's younger brother Aemond foolishly led most of the Green forces defending the city away north to strike at Harrenhal, Rhaenyra's Blacks launched an invasion of the city using a combination of her dragons and the Velaryon fleet. So great was the Gold Cloaks' loyalty to Daemon, however, that there was no siege: they mutinied en masse and threw open the gates of the city to the Blacks. When accused of being turncoats, their leaders responded that Daemon had given them their cloaks, and they were gold whichever way you turned them.
Bronn is not actually named as the new Commander of the City Watch in the books, though Tyrion does name him his Captain of the Guards and works closely with the City Watch. Instead, Tyrion replaces Slynt with Ser Jacelyn Bywater, a poor knight from a lesser branch of House Bywater who is commands the Mud Gate and is hated by Slynt because he's an honest man who performed his duties and refused to take bribes. He dies in the Battle of the Blackwater, when his own Gold Cloaks retreat in a panic when they see Joffrey flee the walls and he tries to rally them back into battle. Jacelyn Bywater's role was functionally condensed with Bronn in the TV series (though Bronn doesn't die in the Battle of the Blackwater). The TV series's version doesn't state why Tywin dismissed Bronn, though it was probably for his low birth (which is one of the reasons he wanted Janos Slynt removed in the books). In either version, Bronn still increased his social position by the time after the battle, by being rewarded with a knighthood.
Note that "Gold Cloaks" is consistently written as two separate words, in both the books and the TV series's published materials (including the subtitles as well as the HBO Viewer's Guide and In-Episode Guides).