DEV Community

loading...

Programmatically get current git branch

Mathieu PATUREL
Don't have much inspiration for an original bio right now...
・1 min read

Nice and easy. Works with git 1.6.3 and higher.

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

Discussion (1)

Collapse
rabbishuki profile image
Rabbi Shuki Gur

You can also use any of the following.

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