Bara bin Azib reported,

When the Prophet ﷺ was prevented from reaching the House, the people of Mecca made a treaty with him stipulating that he could enter it and stay for three days, that he would only enter carrying weapons in their sheaths, the sword in its scabbard, that he would not take anyone from the people of Mecca with him when he left, and that he would not prevent any of his companions who wished to remain there.He said to Ali, "Write down the terms of the agreement between us. In the name of Allah, the Most Gracious, the Most Merciful. This is what Muhammad, the Messenger of Allah, has settled upon."The polytheists said to him, "If we knew you were the Messenger of Allah, we would follow you. Rather, write 'Muhammad bin Abdullah.'"So he ordered Ali to erase it.Ali said, "No, by Allah, I will not erase it."The Messenger of Allah ﷺ said, "Show me its place."Ali showed him the place, and he erased it himself and wrote, "bin Abdullah."He stayed there for three days. When the third day came, they said to Ali, "This is the last day of your companion's agreement, so order him to leave."Ali informed him of that, and he said, "Yes," and departed.Ibn Junab in his narration said "we would pledge allegiance to you" in place of "we would follow you."

Muslim 4631

Sahih

حدثنا إسحق بن إبراهيم الحنظلي وأحمد بن جناب المصيصي جميعا عن عيسى بن يونس واللفظ لإسحق أخبرنا عيسى بن يونس أخبرنا زكرياء عن أبي إسحق

عن البراء قال

لما أحصر النبي ﷺ عند البيت صالحه أهل مكة على أن يدخلها فيقيم بها ثلاثا ولا يدخلها إلا بجلبان السلاح السيف وقرابه ولا يخرج بأحد معه من أهلها ولا يمنع أحدا يمكث بها ممن كان معه قال لعلي اكتب الشرط بيننا بسم الله الرحمن الرحيم هذا ما قاضى عليه محمد رسول الله فقال له المشركون لو نعلم أنك رسول الله تابعناك ولكن اكتب محمد بن عبد الله فأمر عليا أن يمحاها فقال علي لا والله لا أمحاها فقال رسول الله ﷺ أرني مكانها فأراه مكانها فمحاها وكتب ابن عبد الله فأقام بها ثلاثة أيام فلما أن كان يوم الثالث قالوا لعلي هذا آخر يوم من شرط صاحبك فأمره فليخرج فأخبره بذلك فقال نعم فخرج و قال ابن جناب في روايته مكان تابعناك بايعناك

مسلم 4631صحيح
Contents
Reference
Commentary
Ayat
Collection
Sahih Muslim
Book
Jihad and expeditions
Chapter
Treaty of Hudaybiya at Hudaybiya
Numbering
Darussalam 4631
Muslim 4631