To solve the heat equation on $\mathbb{R} \times (0,\infty)$ with the initial condition $g(x)=x^2$ and $g(x)=x$, I did this by guessing that $u(x,t)=x^2+2t$ and $u(x,t)=x$ respectively, are solutions satisfying the initial conditions.
The thing is that the solutions look pretty simple so I was wondering if there is a way to construct these solutions for polynomial initial conditions analytically (and don't guess them) without solving the convolution integral containing the fundamental solution.
Yes, if the initial values on $\mathbb{R}$ are given by a polynomial, then there is a polynomial solution that can be found algebraically. The homogeneity of the heat equation is such that one power of $t$ corresponds to two in the exponent of $x$. (Scaling as $u(cx,c^2t)$.) So, to find a solution with $u(x,0)=x^n$ we should consider the monomials $x^{n-2k}t^k$ for $0\le k\le n/2$. Plugging $$u(x,t)=\sum_{k=0}^{\lfloor n/2\rfloor }C_k x^{n-2k}t^k$$ into the heat equation yields $$u_t-u_{xx}=\sum_{k=1}^{\lfloor n/2\rfloor } k C_k x^{n-2k}t^{k-1} - \sum_{k=0}^{\lfloor n/2\rfloor -1} (n-2k)(n-2k-1) C_k x^{n-2k-2}t^k \\ = \sum_{k=0}^{\lfloor n/2\rfloor -1} \left[(k+1)C_{k+1}-(n-2k)(n-2k-1) C_k\right] x^{n-2k}t^{k-1} $$ The content of the square brackets must be zero, which gives a recurrence relation for the coefficients: $$ C_{k+1} = \frac{(n-2k)(n-2k-1)}{k+1}C_k $$ with $C_0=1$ because the initial condition is $x^n$. It follows that $$ C_k=\frac{n(n-1)\cdots (n-2k+1)}{k!},\quad k=0,1,\dots,\lfloor n/2\rfloor $$
This formula can also be found in EqWorld, where it is split between the cases of even and odd $n$, for no reason that I can see.