DEV Community

Mathieu PATUREL
Mathieu PATUREL

Posted on

Programmatically get current git branch

Nice and easy. Works with git 1.6.3 and higher.

$ git rev-parse --abbrev-ref HEAD
master
Enter fullscreen mode Exit fullscreen mode

Top comments (1)

Collapse
 
rabbishuki profile image
Rabbi Shuki Gur

You can also use any of the following.

Windows: git branch | findstr \*
Linux: git branch | grep \*