"Couldn't find remote ref" error in Bitbucket
Platform Notice: Server and Data Center Only - This article only applies to Atlassian products on the server and data center platforms.
Unable to view the Diff and Commits tab in a Pull request because merge between a branch in forked repository and branch in Main repository gives error
Couldn't find remote ref <ref>
Bitbucket version: 7.7 to 7.11
atlassian-bitbucket.log shows these errors related to branch in question:
DEBUG [http-nio-7990-exec-7] <username> @1Q1D2K7x626x1237485x0 jdsoxe 10.0.16.128,127.0.0.1 "GET /rest/api/latest/projects/<PROJECT-KEY>/repos/<repo-slug>/pull-requests/<ID>/changes HTTP/1.1" c.a.s.i.r.e.ServiceExceptionMapper Mapping ServiceException to REST response 500 com.atlassian.bitbucket.scm.CommandFailedException: '/usr/local/bin/git fetch /var/atlassian/application-data/stash/shared/data/repositories/1820 <branch-ref>:' exited with code 128 saying: fatal: Couldn't find remote ref <branch-ref> fatal: The remote end hung up unexpectedly at com.atlassian.bitbucket.scm.DefaultCommandExitHandler.onError(DefaultCommandExitHandler.java:47) at java.lang.Thread.run(Thread.java:748) ... 287 frames trimmed Caused by: com.atlassian.utils.process.ProcessException: Non-zero exit code: 128 at com.atlassian.bitbucket.internal.process.nu.NioNuProcessHandler.callExitHandler(NioNuProcessHandler.java:277) ... 78 common frames omitted
If you run the Git command on the Git terminal, you'll get the same error:
git fetch /var/atlassian/application-data/stash/shared/data/repositories/1820 <branch-ref> fatal: Couldn't find remote ref <branch-ref> fatal: The remote end hung up unexpectedly
Running the command locally where Bitbucket is running also gives the same error:
/usr/local/bin/git fetch /var/atlassian/application-data/stash/shared/data/repositories/1820 refs/heads/bug/ARGUS-23284 fatal: Couldn't find remote ref refs/heads/bug/ARGUS-23284 fatal: The remote end hung up unexpectedly
This can happen when are using a fork-merge like workflow for your development project, so all your developers always have an up-to-date master in their own fork and they create their own branch and do pull requests to the upstream master. So basically the developers fork the main repository, do development on their own local branch in their own fork and then do pull requests to their own master in the main project.
These errors occur generally when you try to merge changes from a forked repository to the main repository and check the box for "Deleting the source branch", while merging. The missing ref would be the branch you're merging from.
Following are the steps to follow where you can see these errors:
- First create a PR between branch
bug/ARGUS-23284from the fork repo, to the
masterbranch in the main repo:
- Merge the PR, the option for Delete source after merging is checked
- Try to access the Diff tab of the PR, and you see the below error:
This is caused by this bug:
A potential workaround is to upgrade Bitbucket to the 7.12 or above.