The Mitzvah of Emulating Hashem
The Rambam considers “Ve’halachta bidrachav” (You should walk in the ways of Hashem) a mitzvas aseh min haTorah (positive Biblical commandment) and lists it as one of the 613 mitzvos. This mitzvah teaches us that we should be kind and compassionate, and that this behavior should stem from our desire to emulate Hashem. Just like Hashem is called chanun (bestows His kindness upon us even though we are undeserving), similarly, we too should be kind to others and accommodate them without expecting anything in return. In the same vein, we should emulate Hashem by being compassionate, slow to anger, and so on.
Those to whom these positive traits do not come naturally must train themselves to overcome these tendencies: they should go to extremes in practicing the positive trait once, twice, three times, and however long it takes—until the desired behavior comes naturally to them. However, one should not go to an extreme for too long; once they have acquired the desired trait they should return to the middle path. For example, if one is miserly and has difficulty giving money to tzedakah, they should force themselves to give tzedakah liberally; once they have acquired the habit of being generous, they should return to the middle path. There are two exceptions to this rule: anger and arrogance; one must go to the extreme with regard to these two traits, and never get angry or be arrogant. #399