DEV Community

Ante Barišić
Ante Barišić

Posted on

How to get the current git branch name?

An easy way of doing it:

git branch | grep \*

Top comments (3)

Collapse
 
deciduously profile image
Ben Lovy

You can also use __git_ps1:

$ __git_ps1
 (master)
Collapse
 
fennecdjay profile image
Jérémie Astor

This is not working on my machine (running ArchLinux), where is this command from?

Collapse
 
deciduously profile image
Ben Lovy

Hm, I don't remember. It's worked for me on both Gentoo and Debian/Ubuntu (and derivatives), but don't know much about Arch. It's been in my ~/.bashrc for years, I don't know where I got it or why it wouldn't work on Arch.