Menu

Toshimaru's Blog

Get current branch name in Git

You can get current branch name in git as follows:

$ git rev-parse --abbrev-ref HEAD

For example,

$ git branch
* gh-pages
  master

$ git rev-parse --abbrev-ref HEAD
gh-pages

$ echo "Your current branch is $(git rev-parse --abbrev-ref HEAD)."
Your current branch is gh-pages.

See also

Load more