The Shaolin order dates to about 540 A.D., when an Indian Buddhist priest named Bodidharma (Tamo in Chineses) traveled to China to see the Emporer. At that time, the Emperor had ordered the local Buddhist monks to translate Buddhist texts from sanskrit to Chinese. His intent was to allow the general populace the ability to practice this religion.
This was a noble project, but while the Emperor believed this to be his path to Nirvana, Tamo disagreed. Tamo's view on Buddhism was that you could not achieve your goal just through good actions performed by others in your name. At this point the Emperor and Tamo parted ways and Tamo traveled to the near by Buddhist temple to meet with the monks who were translating the Buddhist texts.
The temple had been built years before in the remains of a forest that had been cleared. At the time of the building of the temple, the emperor's gardeners had also planted new trees. Thus the temple was named "young (or new) forest," (Shaolin in Mandarin, Sil Lum in Cantonese).
When Tamo joined the monks, he observed that they were not in good physical condition. Most of their routine paralleled that of the Irish monks of the Middle Ages, who spent hours each day hunched over tables where they transcribed handwritten texts. Consequently, the Shaolin monks lacked the physical and mental stamina needed to perform even the most basic of Buddhist meditation practices. Tamo countered this weakness by teaching them moving exercises, designed to both enhanced ch'i flow and build strength. These sets, modified from Indian yogas (mainly hatha, and raja) were based on the movements of the 18 main animals in Indo-Chinese iconography (e.g., tiger, deer, leopard, cobra, snake, dragon, etc.), were the beginnings of Shaolin Gung Fu.
It is hard to say just when the exercises became "martial arts." The Shaolin temple was in a secluded area where bandits would have traveled and wild animals were an occasional problem, so the martial side of the temple probably started out to fulfill self-defense needs. After a while, these movements were codified into a system of self-defense. The Shaolin practitioner is never an attacker, nor does he or she dispatch the most devastating defenses in any situation. Rather, the study of Gung Fu leads to a better understanding of violence, and consequently how to avoid conflict. Failing that, a Buddhist who refuses to accept an offering of violence (ie, and attack) merely returns it to the sender. Initially, the Gung Fu expert may choose to parry an attack, but if an assailant is both skilled and determined to cause harm, a more definitive and concluding solution may be required, from a joint-lock hold to a knockout, to death. The more sophisticated and violent an assault, the more devastating the return of the attack to the attacker. Buddhists are not, therefore, hurting anyone; they merely refuse delivery of intended harm.