The Prophet ﷺ said, "A Muslim man passed by a thorny branch lying in the road and said to himself, 'I must remove this thorn from the path so it does not injure a Muslim.' So he was forgiven."
حدثنا عفان حدثنا وهيب حدثنا سهيل عن أبيه
عن النبي ﷺ قال مر رجل من المسلمين بجذل شوك في الطريق فقال لأميطن هذا الشوك عن الطريق أن لا يعقر رجلا مسلما قال فغفر له
No references are available.
Suyuti narrated a similar version in Jami Saghir, with the wording, "A man passed by a tree branch on the road and said, 'By Allah, I will remove this from the Muslims so it does not harm them.' So he was admitted into Paradise." Muslim narrated it from Abu Hurairah, and Suyuti indicated that it is sahih.