How to find higher order partial derivative of a multivariate function composition? I came across this formulation, and I cannot work out how to arrive at the final solution:

A step by step, that is first a first derivative and from that the second derivative explanation is what I am looking for. Also an explanation what the equation represents (like in general a normal multivariable function derivative would indicate the slope at a point) would be nice. I am familiar with the basics of calculus and the $\nabla$ operator
 A: Step by Step
To get a concrete understanding, let's go through things in detail
with $n=1$ and $k=2$. I would like to leverage common uses of $x$
and $y$, so instead of thinking of $h\left(g_{1}(x),g_{2}(x)\right)$,
we'll work with $h(x,y)$ and $h\left(g_{1}(t),g_{2}(t)\right)$. I don't know your multivariable calculus and linear algebra background, so let me know if any step below needs explanation.
$\begin{aligned} & f'\left(t\right)\\
= & \dfrac{\mathrm{d}}{\mathrm{d}t}h\left(g_{1}\left(t\right),g_{2}\left(t\right)\right)\\
= & \left.\dfrac{\partial}{\partial x}h\left(x,y\right)\right|_{\left(x,y\right)=\left(g_{1}(t),g_{2}(t)\right)}g_{1}'(t)+\left.\dfrac{\partial}{\partial y}h\left(x,y\right)\right|_{\left(x,y\right)=\left(g_{1}(t),g_{2}(t)\right)}g_{2}'(t)\\
= & h_{x}\left(g_{1}(t),g_{2}(t)\right)g_{1}'(t)+h_{y}\left(g_{1}(t),g_{2}(t)\right)g_{2}'(t)\text{ }(\star)\\
= & \left(\begin{bmatrix}g_{1}'(t) & g_{2}'(t)\end{bmatrix}\begin{bmatrix}h_{x}\left(g_{1}(t),g_{2}(t)\right)\\
h_{y}\left(g_{1}(t),g_{2}(t)\right)
\end{bmatrix}\right)_{1,1}\\
= & \left({\mathbf{g}'(t)}^{\top}\nabla h\left(\mathbf{g}(t)\right)\right)_{1,1}\\
= & \left({\nabla h\left(\mathbf{g}(t)\right)}^{\top}\mathbf{g}'(t)\right)_{1,1}
\end{aligned}
$
Now let's calculate the second derivative, $f''(t)$. The two terms
in ($\star$) will each need to be differentiated, and they are similar
in form, so let's just look at one for now:
$\begin{aligned} & \dfrac{\mathrm{d}}{\mathrm{d}t}\left(h_{y}\left(g_{1}(t),g_{2}(t)\right)g_{2}'(t)\right)\\
= & \dfrac{\mathrm{d}}{\mathrm{d}t}\left(h_{y}\left(g_{1}(t),g_{2}(t)\right)\right)g_{2}'(t)+h_{y}\left(g_{1}(t),g_{2}(t)\right)g_{2}''(t)\\
= & \left(h_{yx}\left(g_{1}(t),g_{2}(t)\right)g_{1}'(t)+h_{yy}\left(g_{1}(t),g_{2}(t)\right)g_{2}'(t)\right)g_{2}'(t)+h_{y}\left(g_{1}(t),g_{2}(t)\right)g_{2}''(t)\\
= & \left(\begin{bmatrix}g_{1}'(t) & g_{2}'(t)\end{bmatrix}\begin{bmatrix}h_{yx}\left(g_{1}(t),g_{2}(t)\right)\\
h_{yy}\left(g_{1}(t),g_{2}(t)\right)
\end{bmatrix}\right)_{1,1}g_{2}'(t)+h_{y}\left(g_{1}(t),g_{2}(t)\right)g_{2}''(t)\\
= & \left({\mathbf{g}'(t)}^{\top}\nabla h_{y}\left(\mathbf{g}(t)\right)g_{2}'(t)\right)_{1,1}+h_{y}\left(g_{1}(t),g_{2}(t)\right)g_{2}''(t)
\end{aligned}
$
Similarly, the derivative of the other term of ($\star$) will be:
$\begin{aligned} & \dfrac{\mathrm{d}}{\mathrm{d}t}\left(h_{x}\left(g_{1}(t),g_{2}(t)\right)g_{1}'(t)\right)\\
= & \left(\begin{bmatrix}g_{1}'(t) & g_{2}'(t)\end{bmatrix}\begin{bmatrix}h_{xx}\left(g_{1}(t),g_{2}(t)\right)\\
h_{xy}\left(g_{1}(t),g_{2}(t)\right)
\end{bmatrix}\right)_{1,1}g_{1}'(t)+h_{x}\left(g_{1}(t),g_{2}(t)\right)g_{1}''(t)\\
= & \left({\mathbf{g}'(t)}^{\top}\nabla h_{x}\left(\mathbf{g}(t)\right)g_{1}'(t)\right)_{1,1}+h_{x}\left(g_{1}(t),g_{2}(t)\right)g_{1}''(t)
\end{aligned}
$
If we add these together to get the entirety of $f''(t)$, we have:
$$
\left(\begin{bmatrix}g_{1}'(t) & g_{2}'(t)\end{bmatrix}\begin{bmatrix}h_{xx}\left(g_{1}(t),g_{2}(t)\right)\\
h_{xy}\left(g_{1}(t),g_{2}(t)\right)
\end{bmatrix}g_{1}'(t)+\begin{bmatrix}g_{1}'(t) & g_{2}'(t)\end{bmatrix}\begin{bmatrix}h_{yx}\left(g_{1}(t),g_{2}(t)\right)\\
h_{yy}\left(g_{1}(t),g_{2}(t)\right)
\end{bmatrix}g_{2}'\left(t\right)\right)_{1,1}
$$
$$
+h_{x}\left(g_{1}(t),g_{2}(t)\right)g_{1}''(t)+h_{y}\left(g_{1}(t),g_{2}(t)\right)g_{2}''(t)
$$
$$
=\left(\begin{bmatrix}g_{1}'(t) & g_{2}'(t)\end{bmatrix}\left(\begin{bmatrix}h_{xx}\left(g_{1}(t),g_{2}(t)\right)\\
h_{xy}\left(g_{1}(t),g_{2}(t)\right)
\end{bmatrix}g_{1}'(t)+\begin{bmatrix}h_{yx}\left(g_{1}(t),g_{2}(t)\right)\\
h_{yy}\left(g_{1}(t),g_{2}(t)\right)
\end{bmatrix}g_{2}'\left(t\right)\right)\right)_{1,1}
$$
$$
+\left(\begin{bmatrix}h_{x}\left(g_{1}(t),g_{2}(t)\right) & h_{y}\left(g_{1}(t),g_{2}(t)\right)\end{bmatrix}\begin{bmatrix}g_{1}''(t)\\
g_{2}''(t)
\end{bmatrix}\right)_{1,1}
$$
$$
=\left(\begin{bmatrix}g_{1}'(t) & g_{2}'(t)\end{bmatrix}\left(\begin{bmatrix}h_{xx}\left(g_{1}(t),g_{2}(t)\right) & h_{yx}\left(g_{1}(t),g_{2}(t)\right)\\
h_{xy}\left(g_{1}(t),g_{2}(t)\right) & h_{yy}\left(g_{1}(t),g_{2}(t)\right)
\end{bmatrix}\begin{bmatrix}g_{1}'(t)\\
g_{2}'(t)
\end{bmatrix}\right)\right)_{1,1}
$$
$$
+\left({\nabla h\left(\mathbf{g}(t)\right)}^{\top}\mathbf{g}''(t)\right)_{1,1}
$$
$$
=\boxed{\left({\mathbf{g}'(t)}^{\top}\nabla^{2}h\left(\mathbf{g}(t)\right)\mathbf{g}'(t)+{\nabla h\left(\mathbf{g}(t)\right)}^{\top}\mathbf{g}''(t)\right)_{1,1}}
$$
Page 86 of Convex Optimization by Stephen Boyd writes this formula in the notation $f''(x)=g'(x)^{T}\nabla^{2}h(g(x))g'(x)+\nabla h(g(x))^{T}g''(x)$.
If we had $k>2$, nothing important about this calculation would change;
we'd just have more terms and so larger vectors/matrices. If we had
$n>1$ things would arguably be more complicated to write, but in
the context of this part of the book, we don't have to care about
$n>1$ because "convexity is determined by the behavior of a function
on arbitrary lines that intersect its domain".
What this Represents
Well, $f''(t)$ is the second derivative of $f$ from single variable
calculus. Its sign tells you if the graph of $f$ is concave up or
concave down at the point. The context (take $k=2$ for simplicity)
with $h(x,y)$ and $\mathbf{g}$ suggests that the height of $f$
at time $t$ is given by the height of some terrain function $h(x,y)$
as we follow a path on the terrain with $x$ and $y$ coordinates
given by $\mathbf{g}(t)$.
We can visualize $h(\mathbf g(t))$ with a picture like this:

$\mathbf{g}(t)$
is represented by the red curve in the $xy$-plane, and the rainbow
terrain represents $h(x,y)$. $f(t)$ is then the height of the blue
path, which is parametrized by $\left\langle g_{1}(t),g_{2}(t),f(t)\right\rangle =\left\langle g_{1}(t),g_{2}(t),h\left(g_{1}(t),g_{2}(t)\right)\right\rangle $.
