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 kingdoms 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 a major attack on King's Landing hasn'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.
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.
After the Battle of the Blackwater, Bronn is relieved of his command of the City Watch after Tywin Lannister returns to King's Landing taking over the duties as official Hand of the King. The City Watch is currently commanded by both Cersei and Tywin Lannister.
In the books
In the A Song of Ice and Fire novels, the goldcloaks are a force of some two thousand men, relatively well-equipped. Whilst 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. It is unknown if the other three cities in Westeros, Lannisport, Gulltown, and White Harbor, or some of the larger towns, have comparable police forces.
Bronn is not actually named as the new Commander of the City Watch in the books, though Tyrion does use him as his personal enforcer and he works closely with the City Watch. Instead, Tyrion replaces Slynt with Jacelyn Bywater, a lowborn but honorable member of the City Watch who is the commander of the Mud Gate, who was hated by Slynt because he honestly performed his duties and refused to take bribes. He died in the Battle of the Blackwater, when his own Gold Cloaks retreated in a panic when they saw Joffrey fleeing the walls. When Jacelyn tried to rally them back to defend the walls, he was killed by his own men. Jacelyn Bywater's role was functionally condensed with Bronn in the TV series (though Bronn doesn't die in the Battle of the Blackwater).