Defining an iterated differential operator with compositions

I'm a bit new to Mathematica so this question might be a bit basic. Still, I could not find an answer.

I wish to define a symbolic differential operator. Currently, I do something like the following:

op[g_] = g'


Now, I would like this operator to work well with compositions. For example I would like

op[g^2].


to return $$2g'*g'$$. However I only get $$(g^2)'$$.

Another thing I'm hoping will work is to compose the operator with itself, so that

op[op[g]]


will return $$g''$$.

I understand that the problem is that the argument 'g' was never defined to be a 'function of x'. But I'm sure how to define everything correctly.

Any help would be appreciated.

You could use the function D:

op[g_] := D[g, x]


In[1]:= op[g[x]^2]

In[2]:= op[op[g[x]]]