Chain rule question

Let $f(x,y)$ and $g(x)$ be continuous functions. Define a new function with $h(x) := f(x,g(x))$. How can I find $h'(x)$? Can someone in the process explain how the chain rule works in this case in an intuitive way, i.e. in terms of the “paths taken” when we do the regular and partial differentiations? (It’s possible to visualize the chain rule using a “tree” that shows all possible “paths” taken toward the end variable.)

-

The trick is to not make $x$ do double duty. Instead of using $x$ as an independent variable, let's use $t$. Then we have $z=f(x,y)$, $x=t$, and $y=g(t)$.
$$\frac{dz}{dt} = \frac{\partial z}{\partial x}\frac{dx}{dt} + \frac{\partial z}{\partial y}\frac{dy}{dt} = f_x(t,g(t)) \cdot 1 + f_y(t,g(t)) \cdot g'(t)$$
If we let $H(u,v) = f(x(u,v),y(u,v))$, where $x$ and $y$ are functions of some further variables $u$ and $v$ then \begin{align*} \frac{\partial H}{\partial u} &= \frac{\partial f}{\partial x}\,\frac{\partial x}{\partial u} + \frac{\partial f}{\partial y}\,\frac{\partial y}{\partial u},\\ \frac{\partial H}{\partial v} &= \frac{\partial f}{\partial x}\,\frac{\partial x}{\partial v} + \frac{\partial f}{\partial y}\,\frac{\partial y}{\partial v}. \end{align*} This is often visualized with "trees" and "paths, as you mention: $$\begin{array}{ccccccccc} & & & & & f\\ & & & & \swarrow & & \searrow\\ & & & x & & & & y\\ & &\swarrow & & \searrow & & \swarrow & & \searrow\\ & u & & & & v & u & & & v \end{array}$$ and the sequence of partials correspond to all ways to get from $f$ to the corresponding variables.
Here, the only difference is that $x$ does not depend on anything, and $y$ depends only on $x$. So we have: $$H'(x) = \frac{\partial f}{\partial x} + \frac{\partial f}{\partial y}\frac{dy}{dx} = \frac{\partial f}{\partial x} + \frac{\partial f}{\partial g}\frac{dg}{dx},$$ where $\frac{\partial f}{\partial g}$ is the partial of $f$ with respect to $y$, with $y$ replaced by $g(x)$. You have to be careful, in that $\frac{\partial f}{\partial x}$ is usually an expression involving $x$ and $y$, and again you have to replace $y$ with $g(x)$. In that respect, it is better to do as Bill Cook suggests and use a different letter for the parameter.