Jenkins and Git: Local Branch No Longer Referencing Corresponding Remote Branch

I need help understanding the following: I’m running a Jenkins job to build out a project hosted in a remote git repo. I am checking out code to a sub-directory, and checking out specific local branch “test-1.1.” I have a corresponding remote branch as well.

However, when I run the Jenkins build, and run git branch -av, I get:

* test-1.1                        f10e15e Commit Text2
* remotes/origin/test-1.1         818da9e Commit Text1

When I manually perform a git clone, and checkout to branch test-1.1, git branch -av gives:

* test-1.1                        818da9e Commit Text1
* remotes/origin/test-1.1         818da9e Commit Text1

It appears that the Jenkins build is doing the branch checkout differently, but I’m not sure how or what.

How would I get Jenkins to checkout the “test-1.1” (or any other) branch and be at the correct hash, and retain the reference to its corresponding remote branch? I could write a shell script, but would there be any other way of doing this that I might be missing?

Jenkins 1.544 with Git 2.0 plugin, CentOS 6.4.

  • GitVersion in a Jenkins Multibranch Pipeline job
  • Jenkins, parameterized builds and the ability to select the required subprojects and child nodes based on variables
  • How to upload a generic file into a Jenkins job?
  • Per branch user axis
  • How/When does Execute Shell mark a build as failure in Jenkins?
  • Automatically setup a JENKINS 2.32.1 server (with a script)
  • Get text from file and display in Jenkins email content
  • How to run Docker inside Jenkins which is running as container
  • 2 Solutions collect form web for “Jenkins and Git: Local Branch No Longer Referencing Corresponding Remote Branch”

    As others already said, Jenkins git plugin has it’s own way of managing the cloning and branches. But it does work. If you want to build branch test-1.1, you type that into the Jenkins job configuration and stop worrying. After the build is finished, you can check from the build page what was the sha of the commit that was built. If it’s not what you expect, only then you should worry.

    (I think the reason for the git plugin’s peculiarities are that it is so versatile: It can build multiple branches in multiple repositories. Because of this it does not check out a branch, but it does build from whatever commit is the latest in the branch(es) you want to build.)

    If you find it difficult to let go of complete control, you always have the option of configuring the job with no SCM and then you can type the commands to do cloning and branch checkout into the build step box.

    Below plugin will help you to parameterized git-hub check out ..see more below

    Git Baby is a git and github fan, let's start git clone.