John Bywater, 21, punched the 52-year-old man after he pulled in to a petrol station on Friarwood Lane in Pontefract, Leeds Crown Court heard.
Bywater also picked up a petrol pump and struck his victim on the shoulder during the incident.
Prosecutor, Jessica Mae Randell said Bywater was riding pillion passenger on a motorbike when he spotted the man riding a Honda CB125 machine in the Pontefract area just before 3pm on November 1.
Bywater attempted to engage the man in conversation when the two bikes stopped in traffic before trying to grab the keys.
The man rode on to the forecourt of a petrol station on Friarwood Lane and fell from his bike as he attempted to turn it around.
Miss Randell said Bywater kicked the man and threw a punch, which connected with his helmet.
Miss Randell said: "He (Bywater) grabbed a petrol pump and swung it, connecting with the complainant's shoulder."
The man managed to escape and ride away.
Miss Randell said the victim previously suffered from anxiety and had to take ten days off work after the incident..
Bywater, of Mulberry Place, Ryhill, admitted attempted robbery.
The court heard Bywater has 15 previous convictions for 30 offences including robbery, attempted robbery, theft of a vehicle and fraud.
He was previously convicted of stealing a motorbike which had been left parked in Hemsworth town centre in July 2018.
Ayesha Smart, mitigating, said at the time of the latest offence Bywater was homeless, was taking cannabis and cocaine every day and was in debt to his drug dealer.
Ms Smart said: "At the time of this offence he was looking for a quick buck.
"This was not a planned offence. Having seen the bike come alongside he took the opportunity and thought he could make some money."
Jailing Bywater for four years, Judge Robin Mairs told him: "I do not accept this was not a planned offence."