How to get the current branch name in Git?

后端 未结 30 2695
清酒与你
清酒与你 2020-11-22 07:47

I\'m from a Subversion background and, when I had a branch, I knew what I was working on with \"These working files point to this branch\".

But with Git I\'m not sur

30条回答
  •  伪装坚强ぢ
    2020-11-22 08:29

    you can also 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 current

    GIT_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 same branch (the current SHA on first build in branch)

    GIT_URL - Repository remote URL

    GIT_URL_N - Repository remote URLs when there are more than 1 remotes, e.g. GIT_URL_1, GIT_URL_2

    GIT_AUTHOR_EMAIL - Committer/Author Email

    GIT_COMMITTER_EMAIL - Committer/Author Email

提交回复
热议问题