The short answer
Gas work starts with a permit and two inspections: a rough piping inspection before anything is covered or the appliance is connected, and a final piping inspection where the pressure test happens (CPC 1203.3). Pipe is sized from the total input of every appliance on the line, assuming all of them run at once (CPC 1208.3). Each appliance gets its own accessible shutoff valve within 6 feet of it (CPC 1212.6), and most get a sediment trap downstream of that valve (CPC 1212.9). The finished system is tested with air, CO2 or nitrogen at not less than 10 psi for at least 15 minutes with no perceptible drop (CPC 1213.3).
If you smell gas
Leave the building, then call the gas utility or 911 from outside. Don't flip switches or use your phone inside.
Permit and the two inspections
A plumbing permit is required before the work, and each building is its own permit (CPC 104.1). The rough piping inspection comes after the pipe is in and before it's covered or any appliance is attached. The inspector checks pipe size, material and installation. The final piping inspection is where the pressure test is run, and once the work passes, the building department can issue a certificate of inspection (CPC 1203.3). The permit holder supplies the test rig, gauges and fittings. The inspector and your city's adopted edition of the code have the final word.
Sizing the pipe by load
Start with the nameplate input rating of every appliance on the system and add them up. The code sizes for the worst case, with all appliances running at full capacity at the same time, and the pipe has to leave each appliance with at least the inlet pressure it needs (CPC 1208.3). A new tankless water heater, range, fireplace or outdoor kitchen can push an older house's gas line past capacity, so the existing line gets re-checked, not assumed. Sizing is done by the longest length, branch length or hybrid method, from tables or equations in the code or from the piping maker's own tables, and the method is written on the plans.
Pipe materials
Steel, stainless steel and wrought-iron pipe has to be at least Schedule 40. Cast iron, PVC and CPVC can't carry fuel gas, and plastic gas pipe has to be polyethylene or polyamide marked for gas, used only outdoors and underground (CPC 1208.5). Underground gas pipe needs at least 12 inches of cover, and 18 inches where vehicle loads or other outside forces could damage it. Steel in the ground needs real corrosion protection, because galvanizing doesn't count (CPC 1210.1). Concealed piping in walls uses approved fittings and stays out of solid partitions. A steel striker barrier protects tubing in hollow walls, and slab-embedded pipe needs approval and 1-1/2 inches of concrete around it (CPC 1210.4).
If the system uses corrugated stainless steel tubing, it has to be bonded to the electrical grounding electrode system with a jumper not smaller than 6 AWG copper and no longer than 75 feet (CPC 1211.2).
Outlet, shutoff valve and connector
A gas stub-out has to stick out at least 1 inch through a finished wall or ceiling and at least 2 inches above a floor or slab. It's capped gastight the moment it's installed and stays capped until the appliance is connected (CPC 1210.8). A system shutoff valve has to be readily accessible and tagged, and each building needs an exterior shutoff that's marked (CPC 1210.9).
At the appliance, an approved manual shutoff valve goes within 6 feet. If a connector is used, the valve goes upstream of it, and a union goes downstream of the valve so the controls can come off. One valve serves one appliance (CPC 1212.6). A listed connector has to be in the same room, and only one connector goes on each appliance (CPC 1212.1).
Sediment trap and the pressure test
A sediment trap goes downstream of the appliance valve, as close to the appliance inlet as practical. It's a tee with a capped nipple in the bottom outlet. Ranges, dryers, gas fireplaces and a few other appliances are exempt (CPC 1212.9). The pressure test is the last step. Low pressure systems get 10 psi for at least 15 minutes. Gas above 14 inches water column, or welded piping, gets 60 psi for at least 30 minutes, and CSST at that pressure gets 30 psi for 30 minutes (CPC 1213.3). Pressure testing is done with air, CO2 or nitrogen, never gas, a flame or oxygen.
What you can safely check yourself
Know where your gas shutoffs are, at the meter and at each appliance, and keep the area clear. You can look at the flexible connector behind your range, dryer or water heater for kinks, crushing or corrosion. Leave capped stubs capped. Don't turn gas valves on or off unless the utility or a plumber has shown you how. Call 811 before digging near a buried line. Don't test, cut, bend or modify any gas pipe yourself.
Questions
Can I add a gas line myself?
The code treats it as permit and inspector work, and testing takes a rig and gauges (CPC 1213.3). A licensed plumber should do it.
How do I know my gas line can handle a new appliance?
Add up the input ratings of every appliance on the line, then check them against the pipe size and length (CPC 1208.3). A plumber does this before the pipe is run.
Does every appliance need a sediment trap?
No. Ranges, dryers, gas fireplaces and a few others are exempt (CPC 1212.9).
Is an earthquake gas shutoff valve required?
The plumbing code requires one only where a local ordinance does. If installed, it has to be certified by the State Architect. Ask your building department.
When to call
For a new range, dryer, water heater, fireplace or outdoor appliance, call or text (760) 912-9831. "Gas line installation" is on our new construction list, and "Gas line repairs" is on our service and repair list.