Before the advent of British to the Indian subcontinent, there was no single entity called India. It was divided into several provinces and ruled by different rulers. Every province was interested in serving their own interest and they was no feeling of a 'nation' as such. But the British imperialism created universal antagonistic attitudes towards the nature of British rule in India. This collective feeling brought the people together against one single cause, i.e. the British. Important role was played by political organisations like Indian National Congress that provided significant leadership.
The role played by western educated elite is quite significant in this regard. Also, with the introduction of railways people got to interact with each other on a large scale and shared common beliefs which acted as an important factor in developing the feeling of oneness among the people of the country. People started to shrug off their identity that was associated with a province and started developing a feeling of nationalism or oneness. A collective identity of India developed with the sense of belongingness for the country- India.