The Prophet ﷺ said, "Whoever swears an oath, let him swear only by Allah." The Quraysh used to swear by their forefathers, so he said, "Do not swear by your forefathers."
عن النبي ﷺ قال: ألا من كان حالفا فلا يحلف إلا بالله فكانت قريش تحلف بآبائها، فقال: لا تحلفوا بآبائكم
Bukhari narrated it in "The Virtues of the Ansar" (3836) and Muslim in "Oaths and Vows" (4:1646), both from Qutayba, and Muslim added others alongside him, they said, Ismail bin Jafar narrated to us, from Abdullah bin Dinar, from Ibn Umar, and he related it.Bukhari also narrated it in "Oaths and Vows" (6648) through another route from Ibn Dinar, with the same chain, but restricting it to only the last part of it, which is his saying, "Do not swear by your fathers."