An energy source excites the electrons of the gas to higher energy levels. These energy levels are quantized.
When the electrons fall back to lower levels, they release energy in the form of light.
The atoms of each element have different energy levels, so the emission spectrum of each element consists of a different pattern of colours.
Hydrogen, with only one electron, gives a rather simple pattern (image 1 below). Helium, with two electrons, gives a more complicated spectrum (image 2 below).
Thus. you can compare the emission spectrum of an unknown gas with the emission spectra of known gases and identify the gas in your tube.