When talking about gcds or primes over the integers, we usually take the positive representative, but that's a convention and we get back and forth by multiplying by $\pm1$.
Working with polynomials over a field, $k[x]$, we usually take a monic representative (lead coefficient 1), and we can get back and forth multiplying by some unit in $k^{\times}$.
Both $\mathbb{Z}$ and $k[x]$ are Euclidean domains (have a division algorithm or Euclidean algorithm), the division algorithm giving a proof that all ideals are principal. A generator for the principal ideal is only determined up to a unit. The units of $\mathbb{Z}$ are $\{\pm1\}$ and the units of $k[x]$ are $k^{\times}=k\backslash\{0\}$.
The Euclidean algorithm produces a generator for the ideal generated by two elements $(a,b)=(d)$ and in fact gives a relation $ax+by=d$.
[In your example, one of the arguments is linear ($x+2$) so the gcd is either going to be $(x+2)$ or $(1)$, and you showed that it is (1). All degree one polynomials are prime/irreducible in $k[x]$, so given another polynomial, either $x+2$ divides it or not.]