I'd like to do a script which, among other stuff, grabs the output of git branch and gets the selected branch. The typical output would be:
master
develop
* release-1.0
...
And I would want to get:
release-1.0
I guess it could be done using开发者_StackOverflow中文版 pipes, but I have not a single clue. Could you mates help me with this? Thanks in advance!
Use the plumbing instead:
branch=$(git symbolic-ref HEAD)
git branch's output is considered porcelain and is not recommended for use in scripts.
line=$(git branch|grep '*')
echo ${line#* }
精彩评论