Magnesium (Mg) is a more reactive metal than the copper (Cu) in the aqueous copper (II) sulfate. When you place a solid Mg ribbon into the blue CuSO4 solution, a metal displacement reaction occurs.
In this reaction, the Mg is oxidized, releasing 2 electrons: Mg-->Mg2+ + 2e-
In this reaction, the Cu2+ in the aqueous solution is reduced as it picks up the 2 electrons released by Mg:
Cu2+ + 2e- --> Cu (solid)
The overall reaction is: Mg(s) + CuSO4(aq) --> MgSO4(aq) + Cu(s); the magnesium, because it is more reactive than copper, displaces it. The blue solution will turn reddish black with the introduction of Mg. This new solution will eventually clear as the reddish copper settles out; MgSO4(aq) is colorless.
Here are metals in order of reactivity: K > Na > Ca > Mg > Al > Zn > Fe > Cu > Ag > Au. Remember that displacement only occurs when a more reactive metal displaces a less reactive one.
No gas is produced in this reaction. However, there is water present in the aqueous solution. Water reacts very slowly with Mg at room temperature, but, if heated, the Mg will react with water to form solid magnesium hydroxide and hydrogen gas. This may have been the gas that was observed, but remember that no gas is produced as a part of the actual displacement reaction described above.