TITLE: Derivation of the formula for Ordinary Least Squares Linear Regression
QUESTION [21 upvotes]: How was the formula for Ordinary Least Squares Linear Regression arrived at?
Note I am not only looking for the proof, but also the derivation. Where did the formula come from?

REPLY [4 votes]: Since the question contains a historical focus, that treatize of Jeffrey M. Stanton on Francis Galton (and Pearson for the extensions) (at the ams) might be what is really wanted . I am surprised, that the wikipedia misses the historical reference completely.
(Cite from the article at AMS:   )

In 1875, Galton had distributed packets of sweet pea seeds to seven
  friends; each friend received seeds of uniform weight (also see Galton
  1894), but there was substantial variation across different packets.
  Galton's friends harvested seeds from the new generations of plants
  and returned them to him (see Appendix A). Galton plotted the weights
  of the daughter seeds against the weights of the mother seeds. Galton
  realized that the median weights of daughter seeds from a particular
  size of mother seed approximately described a straight line with
  positive slope less than 1.0:

"Thus he naturally reached a straight regression line, and the
 constant variability for all arrays of one character for a given
 character of a second. It was, perhaps, best for the progress of the
 correlational calculus that this simple special case should be
 promulgated first; it is so easily grasped by the beginner." (Pearson
 1930, p. 5)