While you are taking a practice swing you accidentally hit your ball. What is the Rule? It depends on where your ball is located.
Ball in the teeing area: If you accidentally knock your ball off the tee while making a practice swing, it doesn’t count as an actual stroke and it is not a penalty. Simply re-tee and play on. Rule 6.2b
Ball on the putting green: While taking a practice swing on the putting green you accidentally hit your ball. You would replace your ball without penalty on the putting green if you accidentally move it in any way, including while taking a practice swing. Rule 13.1d
If you don’t replace the ball back to its original spot you would be playing from the wrong place and would receive a two-stroke penalty.
Ball in fairway, rough, bunker: The Rules of golf say if your ball is in the fairway, rough, bunker or penalty area and you cause it to move with a practice swing, you’ll need to add a penalty stroke to your score and the ball must be replaced. If you do not replace your ball back to the original spot you would be playing from a wrong place and need to add an additional two strokes to your score. Total of three strokes. Rule 14.7a
Here is this month’s golf etiquette tip: When you are in doubt if your ball is lost outside of a penalty area or out of bounds you should always hit a provisional ball.