When a civilization is facing a great crisis, two types of personalities have to take initiative—the warriors (the politicians or men of action), who are capable of winning the support of the population and subduing the enemies, and the philosophers (the men of wisdom and knowledge of religious and philosophical texts), who advise the warriors on morality, righteousness, justice, and political strategy.
In the Mahabharata, the first type of personality is represented by Arjuna, and the second type by Krishna. They come together to save their civilization from a great crisis. Before the great Mahabharata war began, Arjuna was eager for battle. He was constantly making the case for a swift military action, but he was being held back by Krishna who insisted that a war would be too destructive and that they should negotiate to achieve a peaceful solution. But once the war started and the two armies were standing opposite each other, Arjuna wanted to abandon the battlefield because he did not want to commit the sin of mass slaughter, but now Krishna insisted that the war must be fought.
Krishna delivered the sermon of the Gita to Arjuna to make him realize that it was his duty to fight the “dharmayuddha” (the holy war for justice), and that if he walked out of the battlefield he would be committing a grave sin which would lead to the annihilation of their civilization.