Demeaning variables in OLS I am analysing some data in R where I have information on $y$ and $x$.
When I run $y = \alpha + \beta\cdot x$ I get the same coefficient on $x$ (i.e. $\beta$) as when I run
$$y = \beta  \cdot  (x - \bar{x})$$
But when I run
$$y - \bar{y} = \gamma \cdot x$$ I get a different coefficient on $x$.
I am really confused. Isn't the coefficient on $x$ meant to capture the covariance between $x$ and $y$, relative to the variance of $x$?
Why is it that demeaning the outcome variable ($y$) changes the coefficient on $x$ (when there is no intercept), but demeaning the independent variable ($x$) doesn't change it?
I tried to figure it out numerically but cannot recover this paradox.

The intercept-free model with centered $y$

But when I run
$$y - \bar{y} = \gamma . x$$ I get a different coefficient on x.

If you rewrite that equation,
$$y = \bar{y}  +  \gamma  x$$
then you see how it differs from your first case
$$y = \alpha + \beta x$$


The intercept-free model with centered $x$
The surprising part is not that $\beta$ and $\gamma$ are different, but that your second model, where you center the $x$ variable has the same slope with and without intercept.
$$y = \beta  (x - \bar{x})$$
The coefficient $\beta$ is for simple linear regression $y_i = \alpha + \beta x_i + \epsilon$
$$\beta = \frac{\left(\frac{1}{n}\sum_{i=1}^n x_iy_i\right) - \bar{x}\bar{y}  }{\left(\frac{1}{n}\sum_{i=1}^n x_i^2\right)-\bar{x}^2}$$
And for a model without intercept $y_i = \beta z_i + \epsilon$, with $z_i = x_i - \bar{x}$
$$\beta = \frac{\frac{1}{n}\sum_{i=1}^n z_iy_i}{\frac{1}{n}\sum_{i=1}^n z_i^2} = \frac{\left(\frac{1}{n}\sum_{i=1}^n x_iy_i\right) - \bar{x}\bar{y}  }{\left(\frac{1}{n}\sum_{i=1}^n x_i^2\right)-\bar{x}^2} $$
where the second equation occurs when we fill in $z_i = x_i - \bar{x}$

Intuition
One way to see the least squares method is as a orthogonal projection of the observation $\mathbf{y}$ onto the space spanned by the identity vector $\mathbf{1}$ (the intercept) and the vector $\mathbf{x}$ or a matrix $\mathbf{X}$ containing those two vectors.
When the vectors that form that span are orthogonal then the projection is independent from whether or not a particular term is included. The different coefficients can be computed independently.
See also the question Intuition behind $(X^TX)^{-1}$ in closed form of w in Linear Regression . That term $(\mathbf{X^TX})^{-1}$ occurs in the computation of the projection and is a conversion of coefficients based on how much the different columns in $\mathbf{X}$ correlate with each other. It gives a conversion of coordinates $\boldsymbol{\alpha} = \mathbf{X^TY}$ to coordinates $\boldsymbol{\beta} = (\mathbf{X^T} \mathbf{X})^{-1}\mathbf{X^TY}$

When the columns in $\mathbf{X}$ are orthogonal, then the $(\mathbf{X^T} \mathbf{X})^{-1}$ has all the offdiagonal terms zero
$$\beta_i = (\mathbf{X^T} \mathbf{X})^{-1}_{ii}  \mathbf{X^T_i} \mathbf{y} = \frac{\mathbf{X^T_i} \mathbf{y} }{\mathbf{X^T_i}\mathbf{X_i}}$$
