What does git set upstream actually do during a push, and when should you use it?

I often see the --set-upstream flag suggested when doing a git push for the first time. I’ve read parts of the Git manual, but I’m still unclear on what git set upstream really does. How exactly does it affect my local and remote branch relationship, and in what scenarios is it necessary to use?