A nail gun includes a body, a valve unit, a nail striking member and a detector. The body has a nail path, an air chamber, and an intake chamber guiding flow of air into the air chamber. The nail striking member is drivable by air pressure in the air chamber for striking a nail in the nail path. The valve unit is operable to switch between unblocking and blocking states to respectively permit and prevent fluid communication between the intake chamber and the air chamber. The detector is connected pivotally to the body, and is contactable with the valve unit such that, when there is no nail in the nail path, the valve unit is controlled by the detector to be in the blocking state.