"lodging for ships," early 12c., probably from Old English herebeorg "lodgings, quarters," from here "army, host" (see harry) + beorg "refuge, shelter" (related to beorgan "save, preserve;" see bury); perhaps modeled on Old Norse herbergi "room, lodgings, quarters." Sense shifted in Middle English to "refuge, lodgings," then to "place of shelter for ships."
Old English hereborgian, cognate with Old Norse herbergja, Old High German heribergon, Middle Dutch herbergen; see harbor (n.). Figuratively, of thoughts, etc., from late 14c. Related: Harbored; harboring.