The Messenger of Allah ﷺ said, "Whoever takes an oath must swear only by Allah."The Quraysh used to swear by their forefathers, so he said, "Do not swear by your forefathers."
أخبرنا علي بن حجر عن إسمعيل وهو ابن جعفر قال حدثنا عبد الله بن دينار
قال رسول الله ﷺ من كان حالفا فلا يحلف إلا بالله وكانت قريش تحلف بآبائها فقال لا تحلفوا بآبائكم
Muslim narrated it in the chapter on the prohibition of swearing by anything other than Allah, may He be exalted, from the book of oaths, no. 4/1646, from Ali bin Hajar. Bukhari narrated it in the chapter on the days of pre-Islamic ignorance, from the book on the virtues of the Ansar, no. 3836, from the hadith of Ismail bin Jafar, with this wording. It is also found in al-Kubra, no. 4705.