If the developers are working on develop
branch, for a new project
1) Clone
git clone <git_url>
should be able to automatically clone develop
branch locally without using -b
option, so that
$ git branch -a # after clone should give
* develop
remotes/origin/HEAD -> origin/develop
remotes/origin/develop
2) Push
When developer pushes local branch(develop
) changes to remote repository(origin/develop
) using command git push origin develop
, my understanding is, changes are pushed to origin/master
, if remotes/origin/HEAD
points to origin/master
, unlike mentioned in this comment
Question:
1)
Is it recommended to run git remote set-head origin develop
and set HEAD
pointer in remote repository, before performing above two tasks? by any developer
2)
Does git push origin develop
pushes changes origin/develop
irrespective of remotes/origin/HEAD
value in remote repository?
3)
We use webhook between GitLab & Jenkins. Does env.gitlabSourceBranch
provided by GitLab plugin, gives branch name that remotes/origin/HEAD
point to? If yes, how to get the branch name on which, push event happen? through webhook.
Below are the settings done in GitLab, to retrieve branch name on which new commit occured:
Below is the code in Jenkins:
node('worker_node'){
stage('stage1'){
def repoName = env.gitlabSourceRepoName
println "Repository Name: " + repoName // gives correct repo name
def branchName = env.gitlabSourceBranch
println "Branch name: " + branchName // gives always 'master' as value
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…