Octoguys are enemies in Super Mario Galaxy and Super Mario Galaxy 2 that spit rocks to attack. Mario can destroy them by spinning into them and jumping on top of their heads. If Mario gets too close to them, they will run away for a moment, and then resume their attack patterns.
Simply just avoid their rocks, then attack them with a spin or a jump. You can also defeat them by using a Rock Mushroom and crush them with the Power up.