كتاب الإمارة
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 1856 a

It has been narrated on the authority of Jabir who said:

We were one thousand and four hundred on the Day of Hudaibiya. We swore fealty to hiin (the Holy Prophet) and 'Umar was holding the latter's hand (when he was sitting) under the tree (called) Samura (to administer the oath to the Companions). The narrator added: We took oath to the effect that we would not flee (from the battlefield if there was an encounter with the Meccans), but we did not take oath to fight to death.
حَدَّثَنَا قُتَيْبَةُ بْنُ سَعِيدٍ، حَدَّثَنَا لَيْثُ بْنُ سَعْدٍ، ح وَحَدَّثَنَا مُحَمَّدُ بْنُ رُمْحٍ، أَخْبَرَنَا اللَّيْثُ، عَنْ أَبِي الزُّبَيْرِ، عَنْ جَابِرٍ، قَالَ كُنَّا يَوْمَ الْحُدَيْبِيَةِ أَلْفًا وَأَرْبَعَمِائَةٍ فَبَايَعْنَاهُ وَعُمَرُ آخِذٌ بِيَدِهِ تَحْتَ الشَّجَرَةِ وَهِيَ سَمُرَةٌ ‏.‏ وَقَالَ بَايَعْنَاهُ عَلَى أَلاَ نَفِرَّ ‏.‏ وَلَمْ نُبَايِعْهُ عَلَى الْمَوْتِ.
Reference : Sahih Muslim 1856a
In-book reference : Book 33, Hadith 104
USC-MSA web (English) reference : Book 20, Hadith 4576
  (deprecated numbering scheme)