if you run in Jenkins, you can use GIT_BRANCH variable as appears here:https://wiki.jenkins-ci.org/display/JENKINS/Git+Plugin
The git plugin sets several environment variables you can use in your scripts:
GIT_COMMIT
- SHA of the currentGIT_BRANCH
- Name of the branch currently being used, e.g. "master"or "origin/foo"GIT_PREVIOUS_COMMIT
- SHA of the previous built commit from the samebranch (the current SHA on first build in branch)GIT_URL
- Repository remote URLGIT_URL_N
- Repository remote URLs when there are more than 1remotes, e.g. GIT_URL_1, GIT_URL_2GIT_AUTHOR_EMAIL
- Committer/Author EmailGIT_COMMITTER_EMAIL
- Committer/Author Email