When the Prophet ﷺ intended to perform Umrah, he sent word to the people of Makkah asking their permission to enter the city. They stipulated that he could stay no more than three nights, that he could only enter with sheathed weapons, and that he could not invite any of them to Islam.Ali bin Abu Talib began writing the agreement between them. He wrote, "This is what Muhammad, the Messenger of Allah, has agreed upon."They objected, "If we had known you were the Messenger of Allah ﷺ, we would not have prevented you and would have given you our allegiance. But write, 'This is what Muhammad bin Abdullah has agreed upon.'"He said, "By Allah, I am indeed Muhammad bin Abdullah, and by Allah, I am the Messenger of Allah."He himself did not write, so he said to Ali, "Erase 'Messenger of Allah.'"Ali replied, "By Allah, I will never erase it."He said, "Then show me where it is."Ali showed him, and the Prophet ﷺ erased it with his own hand.After he entered Makkah and the days had passed, the people of Makkah came to Ali and said, "Tell your companion to depart."Ali mentioned this to the Messenger of Allah ﷺ, who replied, "Yes." Then he departed.
أن النبي ﷺ لما أراد أن يعتمر أرسل إلى أهل مكة يستأذنهم ليدخل مكة، فاشترطوا عليه أن لا يقيم بها إلا ثلاث ليال، ولا يدخلها إلا بجلبان السلاح، ولا يدعو منهم أحدا. قال: فأخذ يكتب الشرط بينهم علي بن أبي طالب فكتب: هذا ما قاضى عليه محمد رسول الله، فقالوا: لو علمنا أنك رسول الله ﷺ لم نمنعك ولبايعناك، ولكن اكتب: هذا ما قاضى عليه محمد بن عبد الله، فقال: أنا والله محمد بن عبد الله، وأنا والله رسول الله، قال: وكان لا يكتب، قال: فقال لعلي: امح رسول الله. فقال علي: والله لا أمحاه أبدا، قال: فأرنيه، قال: فأراه إياه، فمحاه النبي ﷺ بيده، فلما دخل، ومضت الأيام أتوا عليا، فقالوا: مر صاحبك فليرتحل، فذكر ذلك علي رضي ٱلله عنه الله لرسول الله ﷺ فقال: نعم، ثم ارتحل.
Bukhari related it in jizya and treaties (3184), and Muslim in jihad and campaigns (1873: 92), both from the hadith of Abu Ishaq (that is, Subayi), from Bara, who narrated it.