I'm not a physicist and not great with tensor technicalities but I did have a desire to understand this issue, having encountered the Fisher Information metric in the field of information geometry.
So here's a very informal perspective that connects this to a super basic linear algebra procedure. I think it's roughly correct in spirit and definitely helped me understand this.
This borrows some ideas from MathTheBeautiful's tensor calc series. I'd recommend his video on the covariant basis if you're not familiar with it.
Let $f$ be a function defined in some "raw geometric" coordinate-independent space. Let $\vec{R}$ denote a vector in this space. So $f(\vec{R})$ is the value of $f$ at the point in the space $\vec{R}$. We could think of the "true gradient" (maybe abusing notation) as $\frac{df}{d\vec{R}}$. This gradient is the vector such that the inner product of another vector $v$ in the space with $\frac{df}{d\vec{R}}$ gives you the directional derivative (i.e., the linear part of the increase of $f$ in the direction of $v$ with "speed" proportional to the magnitude of $v$).
Say we have some random coordinate system $\left[s, t, u \right]$. The covariant basis is the set of derivatives of a position vector $\vec{R}$ in the geometric space with respect to each coordinate.
So, at some point of evaluation in our space, the covariant basis will be $\frac{d\vec{R}}{ds}, \frac{d\vec{R}}{dt}, \frac{d\vec{R}}{du} $
The goal is to take the partials of our function $f$ w.r.t. our coordinates ($\frac{\partial f}{\partial s}, \frac{\partial f}{\partial t}, \frac{\partial f}{\partial u} $) that we started with, and use those to get coefficients for our (covariant) basis so that we can express the gradient in the basis.
By definition of the gradient (or you could kind of think about the chain rule), each partial derivative is the inner product of the corresponding basis vector with the gradient,
$\frac{\partial f}{\partial s} = \frac{df}{d\vec{R}} \cdot \frac{d\vec{R}}{ds}$.
This makes sense. The partial w.r.t. $s$ is the directional derivative of $f$ in the direction of $\frac{d\vec{R}}{ds}$, since that's the direction you move when you increase $s$.
Now for what's probably really abusive notation. Let $B$ be the matrix with the covariant basis as column vectors. Then we can express the "vector" of partials as follows
$$
\left(\begin{matrix} \frac{\partial f}{\partial s} \\ \frac{\partial f}{\partial t} \\ \frac{\partial f}{\partial u} \end{matrix}\right) = B^T \frac{df}{d\vec{R}}
$$
We're just matrix-multiplying $B^T$ by the gradient to get the "list" of inner products discussed above.
Let's suppose that we can express the gradient in our basis (our end goal after all). We don't actually know what the coefficients would be but we'll write them down as unknowns and try to recover the coefficients. Suppose
$$
\frac{df}{d\vec{R}} = a \frac{d\vec{R}}{ds} + b \frac{d\vec{R}}{dt} + c \frac{d\vec{R}}{du} = B \left(\begin{matrix} a \\ b \\ c \end{matrix}\right)
$$
Now let's substitue the far-right expression into the above equation for the partials.
$$
\left(\begin{matrix} \frac{\partial f}{\partial s} \\ \frac{\partial f}{\partial t} \\ \frac{\partial f}{\partial u} \end{matrix}\right) = B^TB \left(\begin{matrix} a \\ b \\ c \end{matrix}\right)
$$
Note $B^TB$ is the metric tensor. It's the matrix of all pairwise inner products of our covariant basis vectors. And it should be invertible. So to recover $a$, $b$, and $c$, we just multiply both sides by $(B^TB)^{-1}$.
$$
(B^TB)^{-1} \left(\begin{matrix} \frac{\partial f}{\partial s} \\ \frac{\partial f}{\partial t} \\ \frac{\partial f}{\partial u} \end{matrix}\right) = \left(\begin{matrix} a \\ b \\ c \end{matrix}\right)
$$
The true gradient is some particular linear combination of our covariant basis vectors. The partial derivatives w.r.t. coordinates are each of the respective basis vectors dotted with this linear combination. That's where the metric tensor, the matrix of pairwise inner products of the covariant basis, $B^TB$ comes from. To recover the coefficients of this linear combination, we have to "invert off" the $B^TB$.