git command to get current branch name

Tags: git

When you work with git command line, sometimes you want to know which branch you are working on.

You can use this git command to get current working branch name.

git name-rev --name-only HEAD

To always type this command is quite tedious, therefore we can make alias for this command by making this command to git shell.

git config --global alias.cbn 'name-rev --name-only HEAD'

syntax git config --global alias. x 'command' where x is your alias name for the command. You can make alias for every command instead of typing very long command.

Now we can use alias command name to get current branch name like this.

git cbn

cbn (current branch name)