The question was not how to just get the current branch, thought, right? As pointed out already, `git branch` does that.
The question was how to do it programmatically, and there are multiple ways to do it. You might still call that user interface, but it's that's a stretch; fancy shell magic like branch-in-prompt is typically write-once.