A man who bashed a transgender woman outside a Newtown pub in June narrowly escaped jail time on Tuesday.

Alexis Ozanne, one of two young men charged with bashing 43-year-old Stephanie McCarthy, received 150 hours of community service and an 18-month good behaviour bond after pleading guilty to one count of assault and one count of affray.

He was also convicted and fined $600 for cannabis possession.

In Newtown Local Court, Magistrate Anthony Spence warned the 22-year-old he was "perilously close to a jail term" and he needed to get his "behaviour in check."