what causes green red or black stool

Diet (beets, diets rich in green vegetables, licorice)
Bismuth (for example, Pepto-Bismol)
Gallbladder disease
Celiac disease

Ulcerative colitis
Crohn’s disease
Diverticular disease

Changes in stool color may be due to diarrhea; bleeding in the intestine; diseases of the intestines, liver, or pancreas; and medications
Green stool or poop is a common stool color change. It may be due to bile pigment in the stool because diarrhea moves food too quickly thorough the intestine so the intestinal chemicals and bacteria can’t break down the bile pigment to its normal brown color, or the green color may be due to certain foods like green, leafy vegetables or green food coloring.
Red or black colored stool may be a sign of bleeding in the GI tract (from the esophagus, stomach, small intestine or colon) and should not be ignored.
When stool color changes, what tests need to be done depends upon what cause is suspected for the stool color change. For example, gastrointestinal (GI) endoscopy may be required to evaluate red or black stools if bleeding is suspected.
The treatment for stool color changes is the treatment of the underlying cause