It is often hard to find etymologies for slang. Geek is an exception. The word is older than you might expect, coming from an old English dialect geek or geck meaning a fool or freak, which is attested as early as the 1510s.
This word is descended from the Middle Low German Geck, which likely comes from an imitation of croak. Danish still retains the root word, with the adjective noun gek meaning a crazy person. Old Norse had gikkr meaning a rude person or jester.
Geek developed its modern meaning from US carnival slang. In the 50s Webster’s dictionary defined geek as a “wild man” act, normally involving biting off the head of a snake or chicken. By the 70s this definition remained the only one given in the American Heritage Dictionary. Quite how it obtained its modern meaning is hard to say, but the word was certainly used derogatorily to associate tech literate people with freak shows performers.