(Imām Bukhārī narrates): 'Abdullāh ibn Muhammad narrated to us, he said: 'Abdur-Razzāq narrated to us, he said: Ma'mar informed us, from Hammām, from Abū Hurairah, may Allāh be pleased with him, from the Prophet ﷺ, he said:
The imām is appointed only so that he may be followed, so do not differ from him; so when he performs rukū', you perform rukū'; and when he says "Sami'a Allāhu liman hamidah", you say "Rabbanā laka al-hamd"; and when he performs sajdah, you perform sajdah; and when he prays sitting, all of you pray sitting. Keep the row straight in prayer, because keeping the row straight is part of the excellence of the prayer.
حَدَّثَنَا عَبْدُ اللَّهِ بْنُ مُحَمَّدٍ، قَالَ حَدَّثَنَا عَبْدُ الرَّزَّاقِ، قَالَ أَخْبَرَنَا مَعْمَرٌ، عَنْ هَمَّامٍ، عَنْ أَبِي هُرَيْرَةَ، عَنِ النَّبِيِّ صلى الله عليه وسلم أَنَّهُ قَالَ " إِنَّمَا جُعِلَ الإِمَامُ لِيُؤْتَمَّ بِهِ فَلاَ تَخْتَلِفُوا عَلَيْهِ، فَإِذَا رَكَعَ فَارْكَعُوا، وَإِذَا قَالَ سَمِعَ اللَّهُ لِمَنْ حَمِدَهُ. فَقُولُوا رَبَّنَا لَكَ الْحَمْدُ. وَإِذَا سَجَدَ فَاسْجُدُوا، وَإِذَا صَلَّى جَالِسًا فَصَلُّوا جُلُوسًا أَجْمَعُونَ، وَأَقِيمُوا الصَّفَّ فِي الصَّلاَةِ، فَإِنَّ إِقَامَةَ الصَّفِّ مِنْ حُسْنِ الصَّلاَةِ ".
Reference: Sahih Al Bukhari 722