Scripting git, I need to find out the name of the branch branch. So far this is the only "reliable" way to do this with git branch | sed -n '/^\* /s///p' git branch | sed -n '/^\* /s///p' . (Quotes quotes due to things like color.branch or column.branch in .gitconfig; it is not reliable at all). The only thing I found is git name-rev , but it seems to return the first branch (sorted by name) that points to HEAD:
> git checkout master > git checkout -b another > git checkout master > git name-rev HEAD HEAD another
Is there anything better than sed -n '\#^ref: refs/heads/#s###p' .git/HEAD to figure out the marked branch?
source share