Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Current branch without bloat is to cat .git/HEAD, and if that didn't exist, run git symbolic-ref HEAD. The first is faster and works in the common case where you're in the top of a git repo. In either case, run it through ${branch##*/} to strip down to just the current branch.

I have used this for a long time, never understood how people would put all of git in between them and the next prompt.



Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: