This issue is quite a controversial one. Long Story short it’s okay to move your head a little as long as it’s going in the right direction. On the Backswing the head can move a little to the right and the downswing a little to the left. When I say a little I mean a little. The last thing you want to do is reverse these directions with the head moving to the left and then the right.
This will invariably cause an incorrect weight transfer usually resulting in a reverse pivot. Also as much as you can try keep your head on the same level throughout the swing, meaning not moving it up or down. This will ensure consistency of impact. The ideal position for the head and consequently what I teach is keeping the head on the same angle and height throughout the swing. Setup with your head slightly behind the ball with your eyes peeled at the back. Then keep it in that same position throughout the swing right up until the ball is hit. Once the ball is hit, the head can then go forward.