It is confusing to think of how hockey originated. Three games seem to have made an impact: shinty, bandy, hurley . What is each's particular impact?
But what about field hockey?
Who invented those 4 games? All in Scotland?
I know many people claim they invented field hockey.
I'll touch on ice hockey, as I'm familiar with that:
Officially speaking, the first ice hockey game was played on March 3, 1875 at the Victoria Rink in Montreal, Quebec, Canada. This was recognized by the International Ice Hockey Federation (the governing body of global ice hockey, hereafter just hockey) some time ago), and is widely accepted by hockey historians (which are a thing).
However that doesn't strictly answer the question, as it wasn't like a bunch of people showed up at the Victoria Rink that evening and played a brand-new game (they didn't). What this recognizes is it was the first codified game, specifically played indoors. The sport was not unfamiliar to the wider public (an advertisement the day of in a local newspaper mentions that "A game of Hockey will be played" and that "Good fun may be expected, as some of the players are reputed to be exceedingly expert at the game."), so the question becomes, how did it get to this point?
Therein lies a question that has been contested by hockey historians and fans almost since that very day. The honest answer is there is no definitive answer for the origin of hockey, though there certainly have been serious attempts to find one. The short answer is that stick-and-ball games have been played since the dawn of time, and since people first skated on ice these games would have likely been transferred to that surface, too. There are paintings from at least the 16th century showing life in the modern Netherlands with people on ice holding sticks that looks suspiciously like hockey sticks, with a puck-like object on the ice. Reports of similar games have been found from contemporary reports in the Netherlands, England, Scotland, pretty much anywhere ice formed naturally.
There are multiple reports of similar games taking place in Nova Scotia, in eastern Canada, in the early 1800s (the British had a military presence there), and spread with the soldiers themselves throughout what became Canada. This has led to at three regions in Canada laying claim to be the "birthplace" of hockey: Kingston, Ontario; Windsor, Nova Scotia; and Montreal, Quebec. While arguments can be made for any of the three (though I think Kingston has the weakest argument), the sport kind of amalgamated over time.
That said, the March 3, 1875 game can directly be traced to both Nova Scotia and Montreal: the organizer of that game was a James Creighton, who was originally from Nova Scotia, had moved to Montreal to work and study. He was an avid sportsman, in particular "shinny", a sport similar enough to hockey (played on skates with a stick and ball, albeit outdoors). He had members of the Victoria Skating Club, which he was a member of, and some friends, join up and play a match indoors for the first time in recorded history. Of course the game played that night would hardly be recognizable as hockey today (it had 9 players per side, rather than 6; there was no netting for the goals, just two posts, and goalies had no gear on, neither did anyone else; sticks were much shorter, so players were hunched over; there were no boards along the sides of the ice; forward passing was not allowed; and so on), but it was the start of the game as we now know it.
If you want to read more, there are some solid books on the subject:
Putting A Roof On Winter: Hockey's Rise from Sport to Spectacle by Michael McKinley (2000). The first chapter discusses Creighton, and the origins of the sport itself.
Hockey: A People's History also by Michael McKinley (2006). This is more a look at hockey's role in Canadian history, but it also gets into the origins a little more.
Hockey: A Global History by Stephen Hardy and Andrew C. Holzman (2018). This is a more global look at the sport, and I like it because of that. They took a more extended look at the history of the game in the first couple chapters, and is really good to get into (it also provides citations, if you are looking for that).
On the Origin of Hockey by Carl Gidén, Patrick Houda, and Jean-Patrice Martel (2014). This is the product of several years' research by members of the Society of International Hockey Research (SIHR), a body devoted to the history of hockey. The book looks at nearly every reference to hockey prior to 1875, and attempts to find out where exactly it came from. I must be honest in that I have not personally read it, but it was highly acclaimed by other SIHR members, who I would consider leading authorities on the subject.
Ice hockey is believed to have evolved from simple stick and ball games played in the 18th and 19th centuries in the United Kingdom, Ireland, and elsewhere, primarily bandy, hurling, and shinty. The North American sport of lacrosse was also influential. Arguably the games most influential to the early design of ice hockey were early forms of an organized sport today known as bandy, a sport distinctly separate from ice hockey. These games were brought to North America and several similar winter games using informal rules developed, such as shinny and ice polo, but would later be absorbed into a new organized game with codified rules which today is ice hockey.
The origin of ice hockey was bandy, a game that has its roots in the Middle Ages. Just as for practically all other sports, the game of bandy achieved its modern form during the 19th century in England, more exactly in the Fen district on the East coast. From the Fen district the game was spread to London and from London to the Continent during the second half of the 19th century. British soldiers stationed in eastern Canada brought the game to the North American continent in the 1850's and '60's. You could find similar games there, played by immigrants (chiefly Dutch) and by Indians. Thus there were a number of different games played on skates with a stick and ball and with varying rules in America before ice hockey was invented.