1791, in a South African context, "private military raid undertaken by the Boers against the natives for personal ends," also the name of the leader of the raid and the permission given for it, from Afrikaans commando, "a troop under a commander," from Portuguese commando, literally "party commanded" (see command (v.)).
"A colonist" says he, "who lives two hundred leagues up the country, arrives at the Cape, to complain that the Caffrees have taken all his cattle; and intreats a commando, which is a permission to go, with the help of his neighbours, to retake his property; the governor, who either does not, or feigns not to understand the trick, adheres strictly to the facts expressed in the petition: a preamble of regular information would occasion long delays; a permission is easily given—tis but a word—the fatal word is written, which proves a sentence of death to a thousand poor savages, who have no such defence or resources as their persecutors." [George Carter, "A Narrative of the Loss of the Grosvenor," 1791]
Sense of "elite special forces soldier trained for rapid operations" is from 1940 (originally of shock troops to repel the threatened German invasion of England), first attested in writings of Winston Churchill, who could have picked it up during the Boer War.
Phrase going commando "not wearing underwear" attested by 1996, U.S. slang, perhaps on notion of being ready for instant action.