DEV Community

Ante Barišić
Ante Barišić

Posted on

2

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.

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →