When you feel gas coming on and you feel like you need to fart then just do it and avoid holding the gas in.
You can also relieve gas naturally by applying heat to your belly and sipping on some Gas-Reducing hot tea.
Massaging your lower abdomen can also relieve gas and even simply taking a walk around the block seems to help me when I have gas pain.
If any of those fails you might want to try taking some beano to relieve gas pain in your stomach.