You should be able to tell by the color, and connections used.
Gas
"Black pipe" is commonly used for natural gas, and is dark grey/black.
![enter image description here](https://i.stack.imgur.com/i49WC.jpg)
All connections will be threaded.
![enter image description here](https://i.stack.imgur.com/j3ZdX.jpg)
Water
Water lines come in a variety of materials, some of the most common are.
Copper
This will be um... copper, in color.
![enter image description here](https://i.stack.imgur.com/yXD33.jpg)
While there are other ways to join copper pipes, the most common is solder.
![enter image description here](https://i.stack.imgur.com/pbsPD.jpg)
Galvanized
Galvanized pipes will be a light grey.
![enter image description here](https://i.stack.imgur.com/XX2Sp.jpg)
And use threaded connections similar to black pipe.
![enter image description here](https://i.stack.imgur.com/yFe9t.jpg)
Plastics
You might also find various types of plastic-ish water pipes. These can come in a variety of colors. Red, blue, white, black, etc.
![enter image description here](https://i.stack.imgur.com/kmB1l.jpg)
These may use compression type connections, crimp connections, or various other type or connectors.
![enter image description here](https://i.stack.imgur.com/jPxr3.jpg)
Still can't decide?
Try using your other senses.
Touch the pipe.
If it's warm to the touch, it's likely hot water (may not be warm unless hot water was recently used). Hold the pipe and have a helper turn a nearby tap on/off quickly, to see if you can feel vibrations. Try running the water for a bit, then touch the pipe to see if the temperature changes. If the pipe gets colder/hotter, it's likely a water line.
Listen to the pipe.
Put your ear to the pipe, and again have a helper turn on a nearby tap. If you hear the water clearly in the pipe, you found yourself a water line. (make sure the pipe is not in contact with any other pipes when you do this, since sound could be transferred to the other pipe). This is not the most accurate method, but it can sometimes work.
Taste the pipe.
This won't help you at all. I just pictured people licking pipes in my head, and thought it was funny. You could tell your helper to do it, and then laugh at them when they do it. But it's not going to help you figure out what the pipe is.
Step one would be to check with your local inspection authority. Gas work by non-licensed professionals is prohibited in many jurisdictions.
If it's not prohibited, they may offer advice on material and installation requirements. You can also talk to the employees at a local gas supply store.
A good option for your project would be a direct burial flexible gas line, a.k.a. poly gas pipe. Such a line could be installed so that you have no buried fittings.
Whatever you bury, make sure you place a layer of AT LEAST 6 inches of sand over the line. You should also put a marker tape over the line. The marker tape and the sand serve as indicator to future diggers that something is buried below. Pea gravel below the line is a good idea so that any water that seeps in leaches away quickly and does not stay in contact with the line.
For an example of how to use the sand and marker tape, see the segment of this video from Ask This Old House where they install a blue stone patio. And here's a crude diagram:
![enter image description here](https://i.stack.imgur.com/3y475.png)
Best Answer
You would first turn off the gas at the meter. Then, if this pipe extending from the wall is indeed a gas line, you would take off the cap, clean the threads well, install suitable thread sealer made specifically for gas lines and install an appropriate gas shutoff valve. Install the grill gas connection down flow from this new valve using adapter fittings if necessary.
Then in case you ever need to disconnect the grill for winter, cleaning, replacement, moving or whatever else you can shut off this added valve without having to turn off all the gas in the house.
If you ever do disconnect the grill from the valve it would be necessary to cap off the open valve end for safety sake --- just in case someone comes along and accidentally turns on the valve.