Lewis Hamilton managed to get through the German Grand Prix without much harm, winning a back and forth battle with Ferrari driver Fernando Alonso for a first victory this year.