Sharp pain in upper right abdomen under ribs after eating. How do you know if it's gallstone pain?

Ultrasound. If an ultrasound shows gallstones then it is quite possible. Unfortunately there is no way to say 100% that gallstones are the cause.