As Ross pointed out, and as was previously discussed, we know that
$ (x+a)(x+b) = x(x+b) + a(x+b) = x^2 + bx + ax + ab = x^2 + (a+b)x + ab. $
Therefore, to factor a quadratic expression $x^2 + cx + d$, all one has to do is find two numbers that multiply to $d$ and add to $c$. Let $m$ and $n$ be those two numbers that add to $c$ and multiply $d$. Then:
$ x^2 + cx + d = (x+m)(x+n). $
Note that it doesn't matter which order we pick the two numbers since $a+b = b+a$ and $ab = ba$.
In your case, to factor $x^2 + x - 2 = x^2 + 1x - 2$, we need to find two numbers that add to $1$ and multiply to $-2$. Just by picking and trying different numbers, we find the two numbers are $2$ and $-1$.
A good way to go about finding the numbers is to determine all the factors of the constant term, which for us is $-2$. Since $-2 = 2 \cdot (-1) = (-2) \cdot 1$, we only have to check whether $2 + (-1)$ or $(-2) + 1$ equals one. Since it is the first pair of numbers with this property, these are the two numbers we were looking for. Therefore,
$ x^2 + x - 2 = (x+2)(x+(-1)) = (x+2)(x-1). $
The reason this works: Suppose that we want to factor $x^2 + cx + d$, and we have found the numbers $m$ and $n$ such that $m + n = c$ and $mn = d$. Then:
$ \begin{align} x^2 + cx + d &= x^2 + (m+n)x + mn \\ &= x^2 + mx + nx + mn \\ &= x(x+m) + n(x+m) \\ &= (x+n)(x+m) \end{align} $