The main source of reference is Islam is Al-Quran.
Hadith is the second source and thousands of Hadith are narrated.
Hadith need to be studied carefully since it may be trusted or not.
Hadith should be compared and strengthen with what was taught in Al-Quran.
If Hadith is contradict with Al-Quran, then it may falls into false or misleading hadith.
Before understanding hadith, one need to learn and well verse of how to read and interpret Al-Quran.
Prophet Muhammad has been practicing Al-Quran since he got the first Ayah. While he's doing must be supported by Al-Quran and he will not do something against Al-Quran.
Al-Quran also was sent to him based on Asbab (reason). Thus there are stages and development of how Al-Quran was sent down. There are strategies behind all what Prophet Muhammad has done.
There are two phases of development during Muhammad's life, in Mekah and Madinnah.
In Mekah, Muhammad have faced a lot of challenges from his friends and family. He preached and gathered from his closest family and friends with basic preaching of the true religion of worshipping Allah. Basic teaching is to acknowledge Allah is the only God, other deity and idols are false, improve the relationship within family (i.e. husband and wife, children and parents) and also relationship among humans (i.e. against slavery, killing of children).
With Muhammad challenging and endangering the idols, deity, tradition as well as position of pagan people of Makkah, he was threaten and cast away from his hometown. Negotiation and talks also have been done between the governors of Makkah i.e. Abu Lahab/Jahal which are also his uncle but nothing was accepted to implement Islam in Makkah. Tribal wars happened due to attempt to stop and kill Muhammad.
Thus Muhammad has to find other places that can accept Islam System, which then Madinah peoples willing to accept Islam.
Muhammad was trusted as leader, and he started to develop Madinah and it's people to follow Islam and every aspect. However, people of Makkah still see this as a threat and they started to attack Madinah. War couldn't be avoided and Muhammad, Muhajirin and Ansar has to defend the city.
After several wars, Muslim of Madinah has won most of them and gain strength time by time. The islam system implemented was proven just, and effective which attracted more people to come and stay in Madinah. Everybody from various races and tribes have felt the justice and goodness of Islam System. Several tribes have agreed to live under rule of Islam and Madinah.
When Muslim wanted to enter Makkah for doing Hajj, they was stopped by people of Makkah. Then a treaty of Hudaibiyah was established to list out several do's and don't between people of Makkah and Madinah so that Muslim can enter Makkah in peace to perform Hajj in specific time. With this treaty also, war and killing should be stopped between Makkah and Madinah.
But, people of Makkah later has broken the treaty by attacking and killing a tribe of Muslim people of Madinah. This was seen as a major breach of trust by Nabi Muhammad and Muslim in Madinah.
After this event, the next Ramadhan, Muslim of Madinah gathered in a large number to enter Makkah. The objective is to enter Makkah and stop the pagan system, unjust and cruelty of people in Makkah. with the large numbers, it just shows the strength of Muslim which sent message to the people of Makkah - "We have the strength if we are going to war". So while they enter Makkah, nobody dares to fight them.
Makkah was taken over by Muslim since people has seen how good and peaceful of Islam System in Madinah - no doubt. They are actually willing to have Islam implemented in Makkah and bring back the true religion that has been brought by Ibahim, Ismail and earliest prophet. Only the leaders of Makkah, of course always wanted to retain their wealth and position.
Al-Quran was sent down with reasons. Ayah Al-Quran has to be compared with Sirah/History of Prophet of Muhammad.
Then you will see, why at certain point, Muslim was been asked to involved in war.
Sometimes the war itself does not mean killing others, it's just a war within yourself - to fight the badness within you.
If you read Verse 7 of Surah Ali Imran (3:7), God has made clear statement that for those who wanted deviation, they just made their own interpretation - suitable for them but not suitable to Allah.
So, we need to know what God's want, the objectives of Islam, the strategies by example of Prophet Muhammad from pure heart so that we can interpret Al-Quran justly and correctly.
Alhamdulillah and praise to Allah for all knowledge He has given.