How can I fix Jenkins error due to bad remote git repo
unable to update local ref
git unable to resolve reference refs/remotes/origin
git pull failed unable to resolve reference'' unable to update local ref
error cannot lock ref 'refs/remotes/origin
git pull error unable to resolve reference
unable to resolve reference refs remotes origin feature
git pull bad ref
After trying to run Jenkins tests on a GitHub Pull Request, I'm running into the following error:
error: some local refs could not be updated; try running 00:07:44 'git remote prune email@example.com:myrepo/myrepo.git' to remove any old, conflicting branches
Running any or all of the following does not fix it:
git remote prune firstname.lastname@example.org:myrepo/myrepo.git
git remote prune origin
git fetch origin -t --prune
git gc --prune=now
Jenkins is running this command in its workspace:
git fetch --tags --progress origin +refs/pull/*:refs/remotes/origin/pr/*
Which shows me that there is a bad ref on the remote:
git fetch --tags --progress origin +refs/pul l/*:refs/remotes/origin/pr/* Warning: Permanently added the RSA host key for IP address '126.96.36.199' to the list of known hosts. error: 'refs/remotes/origin/pr/2730' exists; cannot create 'refs/remotes/origin/pr/2730/head' From github.com:myrepo/myrepo ! [new branch] refs/pull/2730/head -> origin/pr/2730/head (unable to update local ref) error: some local refs could not be updated; try running 'git remote prune origin' to remove any old, conflicting branches
There is a ticket closed as
Won't Fix on Jenkins about a similar error: JENKINS-19591
I've tried deleting the remote ref:
git push origin :refs/origin/pr/2730/head Warning: Permanently added the RSA host key for IP address '188.8.131.52' to the list of known hosts. remote: warning: Deleting a non-existent ref. To email@example.com:myrepo/myrepo.git - [deleted] refs/origin/pr/2730/head
I still run into the same error afterwards :-(
How can I fix the remote Pull Request ref?
After checking in
.git/logs/refs/remotes/origin/pr/ I found that the branch it is complaining about is the only one which is a normal file:
$ ls -ld .git/logs/refs/remotes/origin/pr/273* drwxrwxr-x 2 jenkins jenkins 4096 Mar 21 08:05 .git/logs/refs/remotes/origin/pr/273 -rw-rw-r-- 1 jenkins jenkins 248 Mar 21 08:05 .git/logs/refs/remotes/origin/pr/2730 drwxrwxr-x 2 jenkins jenkins 4096 Mar 21 08:05 .git/logs/refs/remotes/origin/pr/2731 drwxrwxr-x 2 jenkins jenkins 4096 Mar 21 08:05 .git/logs/refs/remotes/origin/pr/2732 drwxrwxr-x 2 jenkins jenkins 4096 Mar 21 08:05 .git/logs/refs/remotes/origin/pr/2733 drwxrwxr-x 2 jenkins jenkins 4096 Mar 21 08:05 .git/logs/refs/remotes/origin/pr/2734 drwxrwxr-x 2 jenkins jenkins 4096 Mar 21 08:05 .git/logs/refs/remotes/origin/pr/2735 $ file .git/logs/refs/remotes/origin/pr/273* .git/logs/refs/remotes/origin/pr/273: directory .git/logs/refs/remotes/origin/pr/2730: ASCII text .git/logs/refs/remotes/origin/pr/2731: directory .git/logs/refs/remotes/origin/pr/2732: directory .git/logs/refs/remotes/origin/pr/2733: directory .git/logs/refs/remotes/origin/pr/2734: directory .git/logs/refs/remotes/origin/pr/2735: directory .git/logs/refs/remotes/origin/pr/2736: directory .git/logs/refs/remotes/origin/pr/2737: directory .git/logs/refs/remotes/origin/pr/2738: directory .git/logs/refs/remotes/origin/pr/2739: directory $ find .git/logs/refs/remotes/origin/pr/ -maxdepth 1 -type f .git/logs/refs/remotes/origin/pr/2730 $ cat .git/logs/refs/remotes/origin/pr/2730 0000000000000000000000000000000000000000 0c960f4b8bf30109536ec1b7a1d54a636e21fd87 Jenkins <firstname.lastname@example.org> 1395389111 +0000 fetch --tags --progress email@example.com:TangoGroup/program_creator.git +refs/heads/*:refs/remotes/origin/*: storing head
The contents look a bit strange... not sure whether that's how it is supposed to be...
git push origin :refs/remotes/origin/pr/2730/merge git push origin :refs/remotes/origin/pr/2730/head
to remove the remote PR branches and rerun your Jenkins job.
[JENKINS-18834] Initial git fetch ignore prune settings, UPD: my bad, now I see what happens with Prune in refactoring branch. the prune before, but seems to make a git fetch --prune, which does not fix the problem. 8 more ERROR: Error fetching remote repo 'origin' ERROR: Mark Waite Thanks a lot for taking the time to confirm the bug and write a test. Solution # Go to the Jenkins directory (this can be usually found at C:\Jenkins\Workspace)in which your Jenkins jobs are getting stored, take the back up of your jobs and then delete the job. Please run the job again, your issue would fix and you may not encounter this issue any longer.
Judging by this part:
error: 'refs/remotes/origin/pr/2730' exists; cannot create 'refs/remotes/origin/pr/2730/head'
It seems your Jenkins job has a dirty workspace: it's as if the
.git/logs/refs/remotes/origin/pr/2730/head file exists but it cannot replace it. Not to mention, it's strange that it's trying to create it even though it doesn't exist in your remote.
Do you mind wiping out your workspace? Jenkins has a menu option for that. After you do that, make sure the workspace directory is really deleted. Confirm that by looking directly in the filesystem, if you can.
As you can reproduce the problem by running
git fetch --tags --progress origin +refs/pull/*:refs/remotes/origin/pr/* on another PC, it's evidently not a workspace problem. I think this other question explains well what's going on.
Git Plugin - Jenkins, If the remote URL ends with /.git , a non-bare repository is assumed. (error) Fix object not found exception scanning multibranch pipeline repo (JENKINS-50394) (error) Fix checkout performance regression due to many rev-parse calls (note, some users may depend on the old, poor behavior that the plugin fetched all Go to Windows Services on the slave -- StartMenu, type "services" Select the Jenkins Slave service in the list on the right Right-click and select "Properties" of the Jenkins Slave service Select the "Log On" tab Update the username and password used in manual tests Domain login can be specificied with <DOMAIN>\<USERNAME> Local logins just use <USERNAME> OK to save and exit Right-click again and select "Restart" to make the changes active.
Unfortunately I can't add a comment to the answer (which I think is the appropriate answer). But we encountered this problem on our Jenkins instance yesterday and it had a nuance so I wanted to leave that for future folks in this situation.
For us, deleting the both the 'merge' and 'head' refs did not solve the problem. (It's possible this is because it was based on a pull request coming in from a fork that is not under our control. Note that the branch on that fork was not corrupt.)
Likewise, we attempted to delete the entire PR on the remote reference (basically copy/pasting the answer on this page, and changing the PR #), and that did not solve the problem either. (It deleted cleanly, but quickly re-appeared after I pruned and refetched; it was as if our delete had no effect on the remote.) This is because the pulls reference is read-only.
Oddly, the merge hash will change whenever there is a merge to master, but that remained corrupted for us even when we had merges on our master branch.
Contacting Github support with a clear explanation of the offending branch and the error gave them what they needed to resolve the problem. (From my end, I saw a force-push across all the PRs' merge and head refs.) Obviously you'll want to clearly understand the problem before contacting them, but in our case it was truly on a remote branch that we had no control over.
Git Parameter, This error will occurred when repository not exists or URL is wrong. This error will occurred when is no ssh command on Jenkins master. Step 1 Go to Manage Jenkins -> Manage Plugin. Step 2 Search Github Plugin in the Available tab then click on Download now and install after the restart. Step 3 Under Source Code Management tab, select Git and then set the Repository URL to point to your GitHub Repository. Step 4 Now Under Build Triggers tab, select the “Build when a change is pushed to GitHub” checkbox.
I want to leave a comment here because I encountered issue with same symptoms but with a different root cause. Our Jenkins was running
git fetch --tags --progress -- git@url_of_the_repo.git +refs/pull/*:refs/remotes/origin/pr/*
+refs/heads/*:refs/remotes/origin/* and every PR was outputted as and error
! [new branch] refs/pull/1/head -> origin/pr/1/head (unable to update local ref) error: some local refs could not be updated; try running
The root cause for it was an existing remote branch named
pr. Once the branch was deleted the issue went away.
[JENKINS-54008] Loading library fails, ERROR: Error fetching remote repo 'origin' hudson.plugins.git.GitException: Failed to fetch from https://xxxxxxxx/pipeline-shared/jenkins-pipeline-shared One way to hit this issue is to create a new remote bare repo with no commits and then do git push name-of-the-remote my-special-branch-name which will result in bare repository containing a single branch my-special-branch-name but the HEAD symbolic ref still contains the default value pointing to master. As a result, you'll get the aforementioned warning.
error cloning remote repo 'origin', ERROR: Error cloning remote repo 'origin' hudson.plugins.git. Use SSH URL instead; Use the Jenkins SSH credentials plugin-> This ask related question Under Node properties -> tool locations-> Specify the correct path of I got fatal: protocol error: bad line length character: <htm fatal: the remote It is crucial and mandatory step that you have to setup Git Credentials for accessing Git repo calling from Jenkins Jobs. The Jenkins Credentials can be called by its variable also. This article will help you to setup Jenkins Credentials for Git repo access. It is basic of Jenkins and must read article.
Need your help with github: permission denied to my own repo , remote: Permission to MrsColombo/elsevier-twitter-rest-api.git denied to JuliaRietveld. And there's not much defense I can give for git, it really is that bad. @MrsColombo I had this problem too but managed to solve it, the error is that ur computer has saved a git username and Thanks bro , solved with your answer. I've attached the full console output below, but I had to kill it after about 2 hours of running: Started by user mpugh Building in workspace E:\jenkins\workspace\Person Service Build GIT Debug > git.exe rev-parse --is-inside-work-tree # timeout=10 Fetching changes from the remote Git repository > git.exe config remote.origin.url https://mpugh
jx boot verify-jenkins-x-environment step fail on github enterprise , Summary log STEP: verify-jenkins-x-environment command: /bin/sh -c jx step error: handle dev environment repository: creating remote for dev failed to get repository jenkins-x/jenkins-x-boot-config due to: GET fix: Creating dev env repo should come from GitHub, even with differe… Which is bad. To fix this problem you need to set the slave node tool path, selecting git and setting its value to. C:\Program Files (x86)\Git\bin\git.exe. Location: Configure Node - Tool Locations. This will help you to resolve this particular issue instead of changing global configurations of Jenkins.
- For future googlers: The fix was deleting both the
mergerefs on the remote repo.
- The interesting thing is that this does happen with a clean workspace. I'm thinking the issue is actually on the remote repo somehow. Thanks for pointing out that I should check in
.git/logs/refsinside the workspace.. didn't think to check that yet. Please see my edits above in the question for some more info on what's in there ^^
- If it's a clean clone, and pr/2730 doesn't exist on the remote, then how can it get there in Jenkins? And if you clone the repo on your PC, do you see the same behavior?
- If I do a clean clone on my computer, it does not download the
prrefs, and I only have one HEAD ref:
ls -l .git/logs/refs/remotes/origin/ total 8 -rw-r--r-- 1 jcuzella wheel 197 Mar 21 03:27 HEAD
- The jenkins job is configured to download the other refs with this refspec:
+refs/pull/*:refs/remotes/origin/pr/*, so it's definitely something with the remote
- I am able to reproduce the same problem on my laptop when I do:
git fetch --tags --progress origin +refs/pull/*:refs/remotes/origin/pr/*
- I agree with both of the previous points, but I do not have enough reputation to give feedback in any other way but a new answer.