Especially when they didn’t get along half of the time. From what I understand nations are a fairly new concept. What made them identity as a country with each other and not other surrounding city-states? My knowledge of Ancient Greece is pretty poor so if this is a stupid question then my bad.
Not a stupid question at all!
Identity in Greek antiquity is a fascinating topic. First we have to remove any present-day assumptions that they are a country destined to unite.
Political organization was at the polis level. They were self-governing, autonomous states. Poleis rose up early in the Archaic Period (~800-490 BCE). Each one managed an area usually defined by natural frontiers with the market town centrally located. Thebes in Boeotia, Athens in Attica, etc. They were nations, but smaller than they typical modern-day understanding of the term.
But they were also Greek. In antiquity, “Greek” was a cultural signifier, not a political or national one. Greek peoples spoke the same language, observed the same religion, and inherited the Homeric tradition.
Scholars typically use the term “Greek-speaking peoples” to clarify the distinction : they shared a common culture but not a common state.
But that shared culture was strong.
In 776 BCE, the first Panhellenic games were held in honor of Zeus at Olympia, at the sanctuary of Zeus there. Massive development. There were several sanctuary sites to gods, which were seen as politically neutral, i.e. open to all Greek-speaking people(s). Olympia and Delphi are the most well known.
Games, i.e. athletic contests, were a common way to show celebration and reverence. Homer famously has examples of games celebrated at funerals. The idea of games is that a display of physical excellence in the name of the gods honored them. Thus, they were seen as religious events (and during games there was a truce, a cessation of war—the famous Olympic Truce).
Every four years, poleis would send a delegation of athletes, priests, and statesmen to Olympia for the games. Naturally, these became social events with political m/diplomatic intrigue at times. People came from great distances to compete in or attend the games. (The range of Greek-speaking peoples by the mid-Archaic Period was vast: modern-day Greece, the western coast of modern-day Turkey, southern Italy, Sicily, and coast of Libya.)
How or why the games came to be instituted is not wholly understood. 776 BCE is before the advent of Greek alphabetic writing (~750 BCE). Though later ancient sources have some anecdotes.
The Panhellenic Games were a recognition of the common culture. It is the first expression or event like that in history.
The answer to your question is, then, that poleis were all independent and usually rivals. Any ancient use of “Hellas” was a reference to the lands of Greek-speaking peoples, “Hellenes,” and in no way implied any political union. It was an identity that was shared through the common practice of the Panhellenic games and all they signified.
There is an argument to be made that “Greece” was defined by those who conquered it, e.g. the Ottomans, the Romans, etc.