I have heard majority of people say that there were no sects in the era of Hazrat Muhammad(PBUH).
Then, how and why did the sects in Islam came into being?
It was well known in the time of the Prophet (peace and blessings be upon him) that this Ummah would split into groups
إِنَّ بَنِي إِسْرَائِيلَ افْتَرَقَتْ عَلَى إِحْدَى وَسَبْعِينَ فِرْقَةً وَإِنَّ أُمَّتِي سَتَفْتَرِقُ عَلَى ثِنْتَيْنِ وَسَبْعِينَ فِرْقَةً كُلُّهَا فِي النَّارِ إِلاَّ وَاحِدَةً وَهِيَ الْجَمَاعَةُ
The Children of Israel split into seventy-one sects, and my nation will split into seventy-two, all of which will be in Hell apart from one, which is the main body
and there are many of such Ahadeeth, and many more which go into details, down to what that one group is. As for how the other groups started, then each have their histories.
Sect is made by difference in basic beliefs (not Fiqh or rulings). Any sect claims to have correct beliefs and correct understanding and interpretation and hadith collections of Islam. The main belief that made sect in Islam is Imamat. Imamat is about political leadership of Muslims and how to choose it. This problem basically did not exist before death of Messenger of Allah SAWW because he himself was the leader of Muslims and no one among Muslims wanted to be leader instead of him.
But after death of Messenger SAWW the problem of leadership emerged and Muslims became two main group about how to choose leader (i.e. Caliph). One group believed the leader can be only selected by God and no human has such a right to choose any Caliph. But another group of Muslims rejected this belief and said prophet SAWW did not select any leader for after his death and they themselves selected a leader that he occupied the position of Caliphate. Each group had their own reasoning for their belief from Quran and hadith. This difference in belief about Caliphet and Imamat is the main base of emergence of two main sects in Islam. Also there are many sub-sects inside each of two main sect of Muslims (i.e. Shia and Sunni). For example Kharijates were a different sect.
The Arabic term for sect is Shia. The Prophet SAWW many times used the term "Shia of Ali" and many times said: "O Ali, you and your Shias ..."
For example this is one saying of the Prophet:
O Ali, you the first who enters Heaven and your shias are in chairs of light and they are happy and their faces are lumine around me. ask God forgive their mistakes and they will be my neighbors in Heaven. انت اول داخل الجنة من امتی وان شیعتک علی منابر من نور مسرورون مبیضة وجوههم حولی ,اشفع لهم فیکونون غدا فی الجنة جیرانی
This hadith is mentioned Shia hadith books and Sunni books like these 2 Sunni hadith books: کفایة الطالب، ص135 مجمع الزواید ج 9 ص 131
Prophet Muhammad (PBUH) has two famous sayings about sects of Muslims:
the Judaism nation after Moses (PBUH) became 71 sect that 70 of them are in Hell and 1 in Heaven and Christianity nation after Jesus (PBUH) became 72 sect that 71 of them are in Hell and 1 in Heaven and Islam nation after prophet become 73 sect that 72 of them are in Hell and 1 in Heaven.
(This hadith is narrated by many of Sahabe in both Shia and Sunni hadith books. but the part at the end of some versions saying it is Jamaat (main body) is narrated only by some and is not authentic according to Shia scholars.)
Truth is with Ali and Ali is with Truth
Sects emerge when a group of people are called "out of Islam", "not from true path", deviant, "Bidaati", Murtaad etc. Or it is said that, such and such group is the only follower of true Islam and all others are deviant. Because these words divide the ummah into groups- true muslims and deviants.
But the idea is- unity among ummah is important, but truth is more important. So even in the time of Sahaba, they declared people deviant because of not giving zakat and other reasons. They declared Rafidhis and Kharijis "not from them". So, deviant sects emerged.
So, we should try to unite the ummah. Mere difference of opinions do not make sects. There were difference of opinions even among the sahaba. But calling a group "Bidaati" or "Murtaad" or even "Kafir" should be the last thing to do. Even when sahabas used words like "not from us" for them. A usual way of Salaf was calling the act "bidaat" or calling the belief "kufr" but not calling a group people Bidati/Kafir. May Allah unite the ummah on truth despite some difference of opinions.