If $g:[0,1] \to \Bbb{R}$ such that $g(x)=g(y) \implies g'(x)=g'(y)$ for all $x,y \in (0,1)$, then $g$ is monotonic? Is this true or false?

Let $g:[0,1] \to \Bbb R$ be a function continuous on $[0,1]$ and differentiable on $(0,1)$, such that $g'$ is a function of $g$, i.e. for every $x, y \in (0,1)$, if $g(x) = g(y)$ then $g'(x) = g'(y)$. Then $g$ is monotonic.

I posted my proof as a self-answer, and wonder if there are any easier proofs.
 A: If $g$ is not monotone, then neither is the restriction $\def\eps{\epsilon}g|_{\smash{(0,1)}}$. Non-monotonicity on $(0,1)$ implies the existence of $0<a<b<1$ with (w.l.o.g.)
$$\gamma :=g(a)=g(b)\implies g'(a)=g'(b)=:\gamma'>0$$ 
(I can go into details here if needed, but it is not too hard to see using the intermediate value theorem and the mean value theorem, there are just a lot of annoying details pay attention to). So there is some $\def\eps{\epsilon}\eps>0$ with
$$g(a+x)>\gamma\quad\text{and}\quad g(b-x)<\gamma,\qquad\text{for all $x\in[0,\eps]$}.$$
Define $M:=\{x\in [a+\eps,b-\eps]\mid g(x)< \gamma\}$. Note that $M$ is non-empty, hence we can define $a^*:=\inf M\in(a,b)$. By continuity, we have $g(a^*)=\gamma\implies g'(a^*)=\gamma '>0$, implying the existence of $ \delta>0$ with
$$g(a^*+x) > \gamma,\qquad\text{for all $x\in[0,\delta]$}$$
in contradiction to the choice $a^*:=\inf M$.
$\qquad\qquad\qquad\qquad$
A: Lemma: for any $d \in (0,1)$, if $g'(d) \ne 0$ and $g(d) \ne g(0)$ and $g(d) \ne g(1)$, then $\{ x \in [0,1] \mid g(x) = g(d) \}$ is closed, hence compact; discrete, hence finite; and finally is a singleton.
Proof: WLOG $g'(d) > 0$ (the proof of $g'(d) < 0$ is similar). It is clear that the set is closed, hence compact. Now, if $g(x) = g(d)$, then $g'(x) = g'(d) > 0$, so taking $\varepsilon = g'(x)/2$, we obtain $\delta$ such that $\left| \dfrac {g(x+h) - g(x)} {h} - g'(x) \right| < \dfrac {g'(x)} 2$ whenever $h \in (-\delta, \delta)$, so this is a neighbourhood of $x$ that contains only $x$ from the set, so the set is discrete. Since the set is compact and discrete, it follows that it is finite. Now that it is finite, if it has two distinct points, then there are two distinct points $x_1$ and $x_2$ from the set that are next to each other. But again using epsilon-delta on the derivative of the two points we would find two points between $x_1$ and $x_2$ such that the function is above $g(d)$ at one point and below $g(d)$ at another, and by IVT on the function it would have to pass through $g(d)$ again, contradicting the fact that $x_1$ and $x_2$ are the closest two points from the set.

If the function has positive derivative $g'(x)$ at a point $x$, then there is an open neighbourhood of the point where the function is trapped between two lines with slope $\frac12 g'(x)$ and $\frac32 g'(x)$:


WLOG assume $g(0) \le g(1)$, and we shall prove that $g$ is increasing.
Step 1: $g(1)$ is a global maximum.
Proof: Otherwise, there is $x_0 \in (0,1)$ with $g(x_0) > g(1)$ being the global maximum. To establish a contradiction, we find $x_R \in (x_0, 1)$ such that $g(1) < g(x_R) < g(x_0)$ and $g'(x_R) < 0$. This is a contradiction, as $g(0) < g(x_R) < g(x_0)$, so by IVT there should be $x_L \in (0,x_0)$ such that $g(x_L) = g(x_R)$, but the lemma says that the set $\{ x \in [0,1] \mid g(x) = g(x_R) \}$ is a singleton.
We now find the required $x_R$. First, let $x_1$ be the minimum value after $x_0$ such that $g(x_1) = \frac12[g(x_0) + g(1)]$, which exists because $\{ x \in [x_0,1] \mid g(x) = \frac12[g(x_0) + g(1)] \}$ is closed (hence compact) and non-empty (by IVT). Trivially we have $x_0 < x_1$, and that $g(x) > \frac12[g(x_0) + g(1)]$ whenever $x \in (x_0, x_1)$. We now obtain $x_R$ through MVT at the points $x_0$ and $x_1$.

Step 2: $g(0)$ is a global minimum.
Proof: Similar to Step 1.
Step 3: $g$ is increasing.
Otherwise, there would be $c<d$ such that $g(c) > g(d)$. We let $e$ be the smallest value after $c$ such that $g(e) = g(d)$, and then it is clear that $c < e$ and that $g(x) \in (g(d), g(c))$ whenever $x \in (c,e)$. We use MVT on $c$ and $e$ to obtain $x_R$ such that $g(d) < g(x_R) < g(c)$ and $g'(x_R) < 0$ as before, and derive a contradiction as before, noting that there must be $x_L \in (0,c)$ such that $g(x_L) = g(x_R)$.

A: It is sufficient to show that for each $I\subset[a,b]$, extrema of $g$ on $I$ occurs on the boundary points of $I$. Assume to the contrary that there is 
$$
I =[c,d]\subset[a,b]
$$ such that one of extrema occurs in the interior, not on $\{c,d\}$. We may assume there is $e\in(c,d)$ such that 
$$g(e)\leq g(x) ,\quad\forall x\in [c,d].$$
Further, we may assume that one of $c,d$ is a maximum by shrinking $I$. Hence let us assume without loss of generality that
$c$ is a maximum. Now, by the mean-value theorem, there is $\alpha\in(e,d)$ such that
$$
g'(\alpha)  = \frac{g(d) - g(e)}{d-e}>0.$$
Since $g(e)\leq g(\alpha)\leq g(c)$, the (closed) set
$$
S=\{ \beta \in [c,e]\;|\;g(\beta) = g(\alpha)\}
$$ is non-empty. Let $\beta_0 =\min S$. We will argue by contradiction that $\beta_0 = c$. Assume $c<\beta_0$. Then minimum of $g$ on $[c,\beta_0]$ does not occur at $\beta_0$ since by assumption $g'(\beta_0) = g'(\alpha)>0$. Let the minimum occurs at $\gamma<\beta_0.$ Since
$$
g(\gamma)\leq g(\beta_0)\leq g(c),$$ by Intermediate value theorem, there is $c\leq\beta_1\leq \gamma$ such that $g(\beta_1) = g(\alpha).$ This contradicts minimality of $\beta_0,$ and hence we get $c=\beta_0$. However, this implies that $$
g'(c) = g'(\alpha) >0
$$ and hence $c$ cannot be a maximum on $[c,d]$. This shows that our initial assumption that minimum does not occur on the boundary is wrong, establishing the desired claim.

$\textbf{NOTE:}$ The assumption that $$g(x) = g(y) \Rightarrow g'(x) = g'(y)$$implies that there is a function $\phi(\cdot)$ such that
$$g'(x) = \phi(g(x)).$$ In terms of the differential equation, the equation is called autonomous, and the solution does not depend on $x_0$ of initial condition $(x_0,g(x_0))$. Thus I expected that in fact this claim is true: if $g(x) = g(y)$ for $x<y$, then for all $h>0$, it holds that
$$g(x+h) = g(y+h),$$ though I couldn't prove it.
