I am not sure if I am phrasing my question correctly. Let me put it like this: I have seen plenty of cowboy movies and in pretty much none of them cowboys actually deal with cows.
I might be wrong but as far as I can tell there are two cowboys:
How did the idea of cowboys go from farmworkers to the modern cowboy?
So, this is a very interesting question, though the answer is a bit complex, so bear with me. OP is right, though: the visual image most people have of the "cowboy" (chaps, revolver, hat, rope, etc) was a 19th century American laborer more akin to a modern oil field worker or Alaskan crab fisherman, and not some glamorous Robin Hood figure. So how did a 19th century roughneck turn into a symbol of American individuality that bore little resemblance to the vast majority of its historical counterparts?
The answer: Dime Novels. Dime novels were comic book-esque stories about western culture that ran the gamut from characters, locations, plots, etc. Dime Novels were widely read, and had a massive, almost singular impact on what would evolve into a unique American literary trope (the western). They weren't terribly complex in that the story's hero was always that: a hero to the bone. (The characters weren't exactly layered) They usually revolved around a white man coming into an untamed area (or near one) and saving a woman or family (or idiot) from...well...dark-skinned people. On occasion, there were white villains, but these stories usually towed the disgusting cultural bias of the writers out east who churned them out in a matter of days. Asians, Native Americans, Mexicans, and Jews (perceived threats to Christian civilizing forces) usually swindled, kidnapped, killed, or cheated the "damsel" in distress, and a white male hero rode in and saved the day. It sounds corny and stupid because it is: but really, this was the formula.
Dime Novel writers found that books sold better when they worked in real, notable western figures into the narratives, so people like Kit Carson, Buffalo Bill, and even someone like Jesse James made frequent appearances. Interestingly, social and political shifts altered who could be a "hero" in these stories, so during the economic Panic of the mid-1870s, when people were distrustful of big institutions like railroads and banks, outlaws with hearts of gold became more acceptable in this role.
And here is when the shift begins. Before this time, hunters and trackers were often the heroes in Dime Novels: wild men who lived off the land and represented white America's promise to conquer and tame the vast wilderness. When outlaws became more interesting figures due to cultural shifts mentioned a minute ago, the foundation that existed remained (wild men of the west) and were mixed in with outlaw characters/imagery. This outlaw imagery was all mixed up with the region where these stories were set, which were often mining or cattle towns. In each instance, men on horseback with revolvers and western style clothing were thought to be the norm (even though this wasn't necessarily the case), but writers out east who had never actually seen the things they were writing about ran with that imagery. This imagery was further stained into the imagination of readers by the rise of Buffalo Bill's Wild West, a touring circus of sorts that further played up the imagery of western tropes that are now so ingrained in people's imaginations. Buffalo Bill's Wild West really took off in the 1870s, and toured heavily east of the Ohio River (the idea being that these people who only read about "the west" could now see it for themselves), so this combination of shifting social attitudes, Buffalo Bill's Wild West, and the surge in popularity of Dime Novels all combined to create a very powerful (and enduring) "cowboy" character.
During this period (1870 - 1899 or thereabouts) the basic outlines of the cinematic western archetype found definition. Although a "cowboy" in the real American west of this period was a person who literally worked with cattle (often called "punchers"), their dress and gun belt rig became synonymous with the western white knight hero portrayed in these dime novels. When dime novels fell out of popularity at the beginning of the 20th century, the blueprint was already in place for cinema to piggy-back upon. In other words, the dime novels created the look and narrative foundation for more than a century of artistic representation in film. The story beats were almost identical, as was the look: which is the funny part. The people who wrote the dime novels were almost to a man east coast dandies who had never gone further west than Ohio. These people didn't really know how actual gunslingers spoke, dressed, acted, etc.: thus, what we know of "cowboys" in modern popular culture comes from an exaggerated circus (Buffalo Bill's Wild West) and a literary source that couldn't have been more clueless about the realities of western American culture. Hell, they even got the name wrong, for as already mentioned, "cowboys" were generally people who worked a hellish job that saw them fighting snakes, thunderstorms, and stubborn cows, not outlaws. The combination of Dime Novels, Buffalo Bill's Wild West, and evolving social opinions in the 1870s all came together to form what we understand "cowboy" to be today, at least as a genre aesthetic.
TD;LR - The popular "cowboy" genre trope that most people are familiar with evolved over time, but solidified into what most people know it to be today by way of Dime Novels, Buffalo Bill's Wild West, and a shift in public opinion in the 1870s.
[Sources; Richard Slotkin, 'Gunfighter Nation'; Michael Denning, 'Mechanic Accents']