- Published on
Git Tip: Get Current Branch Name via CLI
Sometimes, you might need to branch name of the current branch that you're working on for various things like automation.
Here's how you can do it:
git rev-parse --abbrev-ref HEAD
rev-parse
-> Revision identifiers--abbrev-ref
-> Specifies the output needs to be abbreviated reference nameHEAD
-> Special reference that points to current commit or branch
How does it work?
It's a shorthand for git checkout @{-1}
. -1
implies that it's the previous branch.
Happy finding name!