When you take an oath about something, you swear to it, affirming its truth. Ironically, if you utter an oath, such as a curse word or obscenity, you also swear. Do you swear to put a quarter in this jar for every time you swear?
The two separate meanings of swear come from branches of the same etymological tree. Both meanings have ties to Old Norse sverja, but sometime in the Middle English, the word became on one hand sweren with the meaning "to promise," while another version, swerian, became "to curse." Both might come from the idea of an oath being connected to a deity, but while one referred to truth, the other went to the dark side, negatively invoking a sacred name.