The primary function of G cells is to secrete gastrin in response to various stimuli, such as the presence of peptides and amino acids in the stomach. Gastrin then stimulates the parietal cells of the stomach to produce and secrete gastric acid (HCl). This gastric acid is essential for the digestion of food and the absorption of nutrients.