Abu Hurairah reported,

The Prophet ﷺ said, "The imam is appointed only to be followed, so do not differ from him. When he bows, bow. When he says, 'Allah hears whoever praises Him,' say, 'Our Lord, to You belongs all praise.' When he prostrates, prostrate. When he prays sitting, then all of you pray sitting. And straighten the rows in prayer, for straightening the rows is part of the excellence of prayer."

Bukhari 722

Sahih

حدثنا عبد الله بن محمد قال حدثنا عبد الرزاق قال أخبرنا معمر عن همام بن منبه

عن أبي هريرة

عن النبي ﷺ أنه قال إنما جعل الإمام ليؤتم به فلا تختلفوا عليه فإذا ركع فاركعوا وإذا قال سمع الله لمن حمده فقولوا ربنا لك الحمد وإذا سجد فاسجدوا وإذا صلى جالسا فصلوا جلوسا أجمعون وأقيموا الصف في الصلاة فإن إقامة الصف من حسن الصلاة

البخاري 722صحيح
Contents
Reference
Commentary
Ayat
Collection
Sahih Bukhari
Book
Adhan
Chapter
Straightening the rows is part of completing the prayer
Numbering
Darussalam 722
Bukhari 722