I have tried what the OP suggests; set the alarm for a couple hours earlier. But getting up at 6am (need to be in the office at 8am) is also hard - it is too easy to turn off the alarm when nothing "bad" will happen (i.e. nobody will get fired) and get a little bit more sleep.
Does anyone have any particular techniques ("hacks" in HN parlance) for making an early wake-up+coding session a habit?