كتاب الإمارة
33  
The Book on Government
(18)
Chapter: It is recommended for the army to swear allegiance to the ruler when intending to fight, and an account of Bay'at Ar-Ridwan beneath the tree
(18)
باب اسْتِحْبَابِ مُبَايَعَةِ الإِمَامِ الْجَيْشَ عِنْدَ إِرَادَةِ الْقِتَالِ وَبَيَانِ بَيْعَةِ الرِّضْوَانِ تَحْتَ الشَّجَرَةِ
Sahih Muslim 1858 a

It has been narrated on the authority of Ma'qil b. Yasar who aaid:

I remember being present on the Day of the Tree, and the Prophet (ﷺ) was taking the oath of the people and I was holding a twig of the tree over his head. We were fourteen hundred (in number). We did not take oath to the death, but to the effect that we would not run away from the battlefield.
وَحَدَّثَنَا يَحْيَى بْنُ يَحْيَى، أَخْبَرَنَا يَزِيدُ بْنُ زُرَيْعٍ، عَنْ خَالِدٍ، عَنِ الْحَكَمِ بْنِ عَبْدِ اللَّهِ، بْنِ الأَعْرَجِ عَنْ مَعْقِلِ بْنِ يَسَارٍ، قَالَ لَقَدْ رَأَيْتُنِي يَوْمَ الشَّجَرَةِ وَالنَّبِيُّ صلى الله عليه وسلم يُبَايِعُ النَّاسَ وَأَنَا رَافِعٌ غُصْنًا مِنْ أَغْصَانِهَا عَنْ رَأْسِهِ وَنَحْنُ أَرْبَعَ عَشْرَةَ مِائَةً قَالَ لَمْ نُبَايِعْهُ عَلَى الْمَوْتِ وَلَكِنْ بَايَعْنَاهُ عَلَى أَنْ لاَ نَفِرَّ ‏.‏
Reference : Sahih Muslim 1858a
In-book reference : Book 33, Hadith 114
USC-MSA web (English) reference : Book 20, Hadith 4586
  (deprecated numbering scheme)