What is the origin of the phrase ‘By the by...’?

Solution 1:

I found the first entries during history, not the exact origin of the expression, unfortunately. They are around the 17th Century.

by the by (earlier by a by, on or upon the by): by a side way, on a side issue; as a matter of secondary or subsidiary importance, incidentally, casually, in passing. Obs. or arch. Also in predicative or complemental use (quasi-adj.):
Off the main track, away from the point at issue, of secondary importance, incidental.

Here are some examples:

  • 1615 W. Hull Mirr. Not intentionally, but accidentally (as we say) vpon the bye.
  • 1627 Hakewill Apol. It led them some other way, thwarting and upon the by, not directly.
  • 1642 Fuller Holy & Prof. St. They had something‥in the favour of Friers, though brought in only by the by.
  • 1678 Butler Hud. All he does upon the By, She is not bound to Justifie.    
  • 1740 J. Clarke Educ. Youth (ed. 3) Let it be done sparingly, and by the bye.

Source: OED

Solution 2:

By the by dates from the 1610’s (confirmed by Alenanno’s data), and the key (and originality) to its etymology is in the second by. Etymonline says of by:

Originally an adverbial particle of place, in which sense it is retained in place names (Whitby, Grimsby, etc.). Elliptical use for "secondary course" (opposed to main) in Old English.

Incidentally, this implies that by the by is the original spelling, while by the bye is now an accepted variant.