git: git branch name programmatically
This is a wiki page. Be bold and improve it!
If you have any questions about the content on this page, don't hesitate to open a new ticket and we'll do our best to assist you.
In a bash script, you can get the current branch's name programmatically thus:
branch_name=$(git symbolic-ref -q HEAD)
Beware, to find a branch name (whether checked out or not) according to a pattern:
git checkout production.release.4.2
production_branch=`git branch | grep "production"`
# May not give the expected result:
# the character $ is being treated as a wildcard and will be expanded, so that the output may include all files in the directory:
# Using double quotes solve the problem:
Issues related to this page:
|Project||Summary||Status||Priority||Category||Last updated||Assigned to|
|Programming||Bash script: how does the $ wildcard work in gi…||active||normal||feature request||7 years 10 weeks|