So, whilst you cannot be prevented from posting it somewhere public, you can (theoretically) be thrown off the course for doing so.
I think there's a unique opportunity for GitHub here. They could give an educational license to verified students in college/high-school/on-line schools. For the duration of their class, they can have as many private repos as they like. When the semester ends, you've got a week to grab your code before it goes public, like a free account. First, it would get students used to GitHub and they would clammer for it in the workplace because they love it so much; Second, it would position GH as a great supporter of education.
I suspect this would catch on better if the repos were destroyed or stayed private. Professors reuse assignments year after year and wouldn't be too happy about public solutions to all their past assignments.
(fwiw, I use Github exactly in this way, only with public repos)
edit for link: https://github.com/edu
Maybe Coursera should host private repos?
Edit- Apparently BitBucket launched a new version of their site only moments after sharing this link. Looks great!
That's like using free speech as a motivation to tell your boss to "Go fuck himself"