Origin: This phrase is from the mid-1800's and originally referred to Native Americans who were often at war with settlers about land rights. The expression meant 'going to war.'
It's a nonsense phrase used when someone is upset or sad. You pat them on the back and say "There, there." You can also say "there, there, everything will turn out right."