How to rotate object whiled keeping aligned to ground normal

I am using this code to keep aligned to the ground normal.

transform.rotation = Quaternion.FromToRotation(Vector3.up, hit.normal);

And this code to rotate on button press.

transform.Rotate(Vector3.up, Time.deltaTime * rotationSpeed,0);

Alone they both work fine but together the object will only align to the ground normal and not rotate. How can I get the two working together?

The button press rotation is probably done before the hit normal code. With the button press rotation, you rotate around the global Y axis while taking into account the previous rotation of the transform. But with the hit normal rotation code, you create a new rotation that ignores what the rotation was before.

With this code, you will instead be using the previous facing direction (that got turned by your button press code), along with the hit normal, to create the new orientation:

transform.rotation = Quaternion.LookRotation(transform.forward, hit.normal);

There is another issue in the button press. You probably want to use transform.up instead of Vector3.up, so that your object rotates around the previous hit normal, rather than the world’s up direction:

transform.Rotate(transform.up, Time.deltaTime * rotationSpeed,0);