Gandhi’s political and moral philosophies are often mixed together, but they are really separate though interconnected things.
His moral philosophy was ahimsa, or non-violence. This is an ancient Hindu concept, first mentioned in the Vedas, and subsequently in the Puranas, Upnishads, and epics such as the Mahabharata. Gandhi was deeply religious and studied these books over many years.
In particular, Gandhi referred to the Mahabharata, which follows the Yajur Veda in saying "ahimsa parmo dharma", meaning "non-violence is the fundamental virtue". The Mahabharata has a section called the Bhagavad Gita which consists of a dialog between Arjun (a warrior) and Krishna (a manifestation of the god Vishnu). The context is the battle of Kurukshetra. Arjun is reluctant to fight against an army consisting of his cousins, uncles, and other relatives. Krishna explains the concept of a lawful or just war, and Arjun is convinced.
Gandhi was conflicted over this. He was a pacifist by nature and he interpreted the Gita as allegory -- the battlefield isn’t real, it’s a metaphor for man’s soul, the war is between his good and evil impulses. But he wasn’t totally happy with this interpretation either. During WW2 he openly supported the British against Nazi Germany. It was largely due to his agreement with Viceroy Lord Linlithgow that turned the Indian National Congress around to support the British, and convinced 2.5 million Indians to volunteer to fight the Axis.
Moving on, his political philosophy was non-cooperation. Ahimsa guided him to the extent that he rejected any violent means of overthrowing the British. But he acknowledged that ahimsa alone wasn’t going to win independence for India.
He framed it as "satyagraha" which means "an insistence on truth". It was a moral argument in favor of the right to self-determination: the freedom to choose your own actions, and a prohibition against compelling others. Each person is free to choose his own actions including the freedom to disobey unjust laws.
At the peak of British occupation, there were about 40,000 British officials in India, including around 20,000 military. The Indian population was around 300 million, a ratio of 15,000 Indians per British soldier. British rule could only work with Indian cooperation. Gandhi figured that if Indians simply refused to cooperate with the British, they would be unable to govern India. They couldn’t very well kill hundreds of millions of people.
Gandhi’s first act of non-cooperation was the salt march. Under British law, Indians were not permitted to manufacture salt, which is a basic requirement for life in the tropics. They had to purchase salt from the British. Gandhi led a group of Indians to the coast to make salt from sea water in defiance of British law. The British had no choice but to respond, which they did by beating the marchers to a bloody pulp with batons, and imprisoning many of them. Gandhi had instructed his people to offer no resistance -- just take the beating, and then if you have strength enough, keep walking or crawling to the coast to make salt.
This incident was widely reported in the international press and it put the Brits on the defensive, by highlighting the unfairness of the law and the brutality of enforcement. Sympathy for the British eroded across Europe and in Britain itself, where Parliament was divided. Other non-cooperation actions followed, making the British respond with increasing force against Indians who refused to obey the law but also refused to resist the beatings. It became very hard for the British to make a moral argument for occupation, and non-compliance with the laws also began to hurt their treasury.
So non-violence was the philosophical basis, but the political action that followed was non-cooperation. That was Gandhi’s strategy for independence.