Ibn ʿAbbas said, "Messenger of Allah ﷺ set out from Medina to Mecca and he fasted till he reached 'Usfan, where he asked for water and raised his hand to let the people see him, and then broke the fast, and did not fast after that till he reached Mecca, and that happened in Ramadan." Ibn ʿAbbas used to say, "Messenger of Allah ﷺ (sometimes) fasted and (sometimes) did not fast during the journeys so whoever wished to fast could fast, and whoever wished not to fast, could do so." (Using translation from Bukhārī 1948)
خَرَجَ رَسُولُ اللهِ ﷺ مِنَ الْمَدِينَةِ إِلَى مَكَّةَ فَصَامَ حَتَّى بَلَغَ عُسْفَانَ ثُمَّ دَعَا بِمَاءٍ فَرَفَعَهُ إِلَى يَدِهِ لِيُرِيَهُ النَّاسَ فَأَفْطَرَ حَتَّى قَدِمَ مَكَّةَ وَذَلِكَ فِي رَمَضَانَ وَكَانَ ابْنُ عَبَّاسٍ يَقُولُ قَدْ صَامَ رَسُولُ اللهِ ﷺ وَأَفْطَرَ فَمَنْ شَاءَ صَامَ وَمَنْ شَاءَ أَفْطَرَ