In S2E10 "Valar Morghulis" of Game of Thrones, Qhorin Halfhand started provoking and attacking Jon Snow. Why was this?
My only thought was that it was to make the Wildlings trust Jon but I don't see how it achieves that!
When Halfhand and Jon Snow are the lone survivors of their patrol and are captured by the wildlings, Halfhand orders Jon Snow to defect. The scene which you are questioning is where the actual deed transpires.
Halfhand knows that once they reach the Wildling's camp, both of them will be killed or worse, first tortured and then killed. He can also sense that their only chance is if they can convince the Wildling's that Jon Snow is no more a Crow . But for that they needed a substantial hook. Thus, Qhorin Halfhand engages Jon Snow in a mock fight which leads to Jon Snow claiming Halfhand's life (which was what Halfhand intended to happen).
Due to this act of his, Jon Snow is able to convince the Wildlings that he never really wanted to be a Night's Watch ranger and despised their authority.
KeyBrd Basher's answer is correct in relation to the tv-shows.
However, I will add some further clarification from the books:
[A Clash of Kings spoilers ahead]
In the previous scenes, the wildlings are on Jon and Qhorin's tracks in the Skirling Pass. Qhorin urges Jon to yield once they are caught, and pretend to be a turncloak. He then makes Jon recite his vows to ensure that he never forgets that he is truly a crow, and makes Jon promise that he will not "balk whatever they ask [of him]".
[Qhorin]:“If we are taken, you must yield.”
[Jon]:“Yield?” He blinked in disbelief. The wildlings did not make captives of the men they called the crows. They killed them, except for... “They only spare oathbreakers. Those who join them, like Mance Rayder.”
[Qhorin]:“And you.”
[Jon]:“No.” He shook his head. “Never. I won’t.”
[Qhorin]:“You will. I command it of you.”
-A Song of Ice and Fire: A Clash of Kings, Chapter Sixty-Eight (Jon VIII).
Qhorin at this point knows that the wildlings would want Jon to kill him in order to prove his allegiance to them, but Jon doesn't until the last moment (Qhorin keeps asking Jon "is your sword sharp?").
It is important to note here that it was the wildlings themselves (Rattleshirt AKA The Lord O' Bones) who wanted Jon to kill Qhorin Halfhand to prove his defection:
The big spearwife narrowed her eyes and said, “If the crow would join the free folk, let him show us his prowess and prove the truth of him.”
“I’ll do whatever you ask.” The words came hard, but Jon said them.
Rattleshirt’s bone armor clattered loudly as he laughed. “Then kill the Halfhand, bastard.”
“As if he could,” said Qhorin. “Turn, Snow, and die.”
And then Qhorin’s sword was coming at him and somehow Longclaw leapt upward to block.
-A Song of Ice and Fire: A Clash of Kings, Chapter Sixty-Eight (Jon VIII).
They then have an epic and ridiculously depressing sword-fight, at the end of which Ghost bites Qhorin's leg and Jon takes the opportunity to slay Qhorin.
This seems to appease the wildlings and Rattleshirt begrudgingly allows Jon to make his case with Mance.
It is also important to note that Qhorin Halfhand is somewhat of a hero among the Night's Watch, and is well-known, feared and respected by the wildlings (he had in fact recently killed Alfyn Crowkiller in a one-on-one duel), so by killing him (no easy feat), Jon has quite well shown his allegiance to the wildlings!
Both answers are excellent, but I feel it needs to be added that Qhorin attacked Jon because he knew Jon wouldn't attack him.
This is partly because Jon is loyal, partly due to his respect for Qhorin, and partly because Jon is not the type of person who would sacrifice another to save himself. Rather, Jon is the type of person who would sacrifice himself to save others.
It was a practical decision to force Jon's hand, and by extension save Jon, and hopefully, the Night's Watch itself.