I set out with the Messenger of Allah ﷺ on a military expedition. My camel grew slow and exhausted, so the Messenger of Allah ﷺ arrived before me. I arrived in the morning and went to the mosque, where I found him at its door.He asked, "Have you only just arrived?"I replied, "Yes."He said, "Leave your camel and go in to pray two units of prayer."So I went in and prayed, then returned.
خرجت مع رسول الله ﷺ في غزاة، فأبطأ بي جملي وأعيا. ثم قدم رسول الله ﷺ قبلي، وقدمت بالغداة، فجئت المسجد فوجدته على باب المسجد. قال: الآن حين قدمت؟ قلت: نعم، قال: فدع جملك وادخل فصل ركعتين قال: فدخلت فصليت، ثم رجعت.
Bukhari narrated it in the Book of Sales (2097), and Muslim narrated it in the Book of the Prayer of Travelers (73/715), both through the route of Abdul-Wahhab Thaqafi, who said, Ubaydullah narrated to us, from Wahb bin Kaysan, from Jabir bin Abdullah, mentioning the same thing. The wording given here is that of Muslim, while Bukhari's wording is longer than this and will come later in the Book of Sales and in other books.Some narrators abbreviated it with the wording, "I came to the Prophet ﷺ while he was in the masjid, and he said, 'Pray two rak'ahs.'" So they included the hadith of Jabir under two headings, the chapter on what has been said about greeting the masjid with prayer, and the chapter on the two rak'ahs in the masjid for one who has returned from a journey, as Nawawi did in his arrangement of the chapters of Muslim.