Craig Moore, 25, admitted carrying out the attack on Michael Martin, the uncle of his baby daughter, at the city's Chambers Street in November last year. The court was told there had been ongoing difficulties between the families.
Sheriff Frank Crowe told Moore: "To ensure we deal with these matters in a civilised way it is important for court users that there is a safe environment to carry out this business.
"But it does seem you used this venue and took this opportunity to assault Mr Martin."
Fiscal depute Aidan Higgins said: "Mr Martin had attended at the sheriff court and in the course of the morning he went out to buy cigarettes.
"He was making his way back to Chambers Street and was on his mobile phone and at that point the accused ran from the other side of the street and struck Mr Martin on the head with a baton several times and caused him to drop his mobile phone."
The sheriff deferred sentence on Moore, of Ligerwood Farm Cottages, Dalkeith, for background reports.