Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-65183

Default branch handling is missing in pipeline git step

      Currently many GitHub projects are changing the default branch from master to main.  Some projects have both branches.  The following produce different results:

      Shell:

      git clone url #checks out main
      

      Pipeline:

      git 'url' # checks out master 

      It is certainly possible to specify a branch in both git and checkout step, but the default behavior is unintuitive.  As the default branch switch to main continues, I expect to encounter many (more) projects that have both branches (for better or for worse).

      I noticed that docs were recently updated (JENKINS-64320), but I don't believe that every job referencing a repository (in this way) should change when the upstream default branch configuration changes.

          [JENKINS-65183] Default branch handling is missing in pipeline git step

          Mark Waite added a comment - - edited

          I'm open to suggestions of command line git techniques that can be used to determine the name of the default branch on the remote while still living within the limitations of the git plugin implementation. I've not been able to find a command or commands that will consistently report the default remote branch name using command line git 1.8 through 2.31.0.

          I'm not willing to replace the existing init/fetch/checkout sequence with clone because it would sacrifice compatibility. Let me know if you find a way to request the name of the default remote branch. I'm also open to consider using JGit to determine the default remote branch name, though I assume that if JGit has the ability to ask that question, then command line git can do it as well.

          Stackoverflow looks promising at https://stackoverflow.com/questions/50481123/get-the-default-branch-of-a-remote-repository-with-jgit

          It looks promising that git remote show origin might be filtered to find the value of HEAD branch. Works even on CLI git 1.8.3 on CentOS 7, though it will need to be an authenticated call, because it relies on git ls-remote to retrieve that info.

          Mark Waite added a comment - - edited I'm open to suggestions of command line git techniques that can be used to determine the name of the default branch on the remote while still living within the limitations of the git plugin implementation. I've not been able to find a command or commands that will consistently report the default remote branch name using command line git 1.8 through 2.31.0. I'm not willing to replace the existing init/fetch/checkout sequence with clone because it would sacrifice compatibility. Let me know if you find a way to request the name of the default remote branch. I'm also open to consider using JGit to determine the default remote branch name, though I assume that if JGit has the ability to ask that question, then command line git can do it as well. Stackoverflow looks promising at https://stackoverflow.com/questions/50481123/get-the-default-branch-of-a-remote-repository-with-jgit It looks promising that git remote show origin might be filtered to find the value of HEAD branch . Works even on CLI git 1.8.3 on CentOS 7, though it will need to be an authenticated call, because it relies on git ls-remote to retrieve that info.

            Unassigned Unassigned
            akom Alexander Komarov
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: