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.

It is not necessarily true that $\operatorname{cov}(x, y) / \operatorname{var}(x)$ is the slope in the case that there is no intercept.
The solution to the least squares problem for simple linear regression is easier to see if we write the formula for the slope equivalently as the following assuming an intercept term:
$$\hat{\beta} = \frac{\sum_i ((y_i - \bar{y})(x_i - \bar{x}))}{ \sum_i (x_i - \bar{x})^2}$$
but if there is no intercept the solution is
$$\hat{\beta} = \frac{\sum_i (y_ix_i) }{ \sum_i (x_i^2)}$$
Now the two are equal if $x_i - \bar{x}$ is used in place of $x_i$ in the latter as the denominators are then clearly the same and the numerators are equal because $\sum_i (-\bar{y}(x_i - \bar{x}))$ is zero but, in general, the two are not  equal.
The place this often appears is when deriving $R^2$ since one then needs to use corresponding formulas for intercept and no-intercept cases.
Notice that if we use $\alpha + \beta(x_i - \bar{x})$ that the intercept and slope columns of the model matrix, i.e. a column of 1's and a column equal to $x - \bar{x}$, are orthogonal so the projection onto the latter is independent of the intercept; however, if we remove $-\bar{x}$ then they are no longer necessarily orthogonal.
