Skip to content

Instantly share code, notes, and snippets.

@mikemclin
Created February 9, 2015 15:12
Show Gist options
  • Save mikemclin/116afef8628c2f2cba91 to your computer and use it in GitHub Desktop.
Save mikemclin/116afef8628c2f2cba91 to your computer and use it in GitHub Desktop.
Store Git branch name into variable
# Store the current Git branch
branch_name=$(git symbolic-ref -q HEAD)
branch_name=${branch_name##refs/heads/}
branch_name=${branch_name:-HEAD}
# Do something
git checkout master
git merge $branch_name
git checkout $branch_name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment