Sayyiduna Jabir bin Abdullah (may Allah be pleased with them) narrates: The wife of Sayyiduna Zaid bin Harithah (may Allah be pleased with them), Sayyidah Umm Mubashshir (may Allah be pleased with her), said to me: The Messenger of Allah (peace and blessings be upon him) came to me in my garden and said: "O Umm Mubashshir! Who planted these (date palm) trees? A Muslim or a disbeliever?" I replied: A Muslim did. He (peace and blessings be upon him) said: "Whoever among the Muslims plants a tree, then if any person, animal, or bird eats from it, it is charity for him (i.e., the Muslim who planted the tree will receive the reward of giving charity)."
From this hadith, it is understood that planting trees, and in other narrations, engaging in agriculture as well, carries great reward and merit. Any Muslim who plants a tree or cultivates crops, and whatever is eaten from it, it is charity (sadaqah) for him.
In a narration of Imam Muslim rahimahullah, it is mentioned that this is a continuous charity (sadaqah jariyah), and he will continue to receive its reward until the Day of Judgment, as long as that tree remains and continues to bear fruit.