0

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 pipes, but I have not a single clue. Could you mates help me with this? Thanks in advance!

2
  • "The typical exit", you mean the output right? Commented Aug 30, 2011 at 8:19
  • 1
    Oh god, I couldn't remember how was this called. Thanks Commented Aug 30, 2011 at 8:20

2 Answers 2

2

Use the plumbing instead:

branch=$(git symbolic-ref HEAD)

git branch's output is considered porcelain and is not recommended for use in scripts.

Sign up to request clarification or add additional context in comments.

2 Comments

And massage it with sed to remove the refs/heads portion: sed -e 's,.*/,,'
Whoa, I didn't know that. Could sed be piped too?
1
line=$(git branch|grep '*')
echo ${line#* }

1 Comment

Thanks, that was what I needed. However, @holygeek has the answer and an advice!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.