Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Fetch the Bitbucket Pull Request to local repository

Jaroslav Libal August 17, 2014

Hello,

I would like to fetch the pull request from my Bitbucket project (private repository) to my local git repository to be able to do some tests before merge etc.

So I have tried (according to docs and this QA forum) this request:

$ git fetch origin pull/3/head


However - what can I do when I get those messages:

fatal: Couldn't find remote ref pull/3/head
fatal: The remote end hung up unexpectedly

4 answers

1 accepted

0 votes
Answer accepted
John Garcia
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 17, 2014

This feature is not supported at this time. It would be reasonable to compare the branches using this suggestion: http://stackoverflow.com/questions/822811/showing-which-files-have-changed-between-git-branches

Jaroslav Libal August 17, 2014

Hello, thanks a lot for your answer. Yes, I am able to diff the branches; however it is quite strange for more complicated pull requests and bigger projects from my point of view.

John Garcia
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 17, 2014
5 votes
John DiBaggio August 16, 2016

The following worked for me, for checking out a pull request locally:

git fetch origin refs/pull-requests/<pull request number>/from:<new local branch name>

From there, you can do tests, merge this branch into another branch, etc.

Daniel Shifflett September 13, 2018

Exactly what I needed. Just checkout the new local branch and voila

Thanks

Chi Fung Wong September 21, 2018

Not working for me,  I see this error:

$ git fetch origin refs/pull-requests/1/from:test 

fatal: Couldn't find remote ref refs/pull-requests/1/from
Like # people like this
vadivelpm February 2, 2019

For me also not working

Like JerseyStan likes this
Joy Wang April 2, 2019
git config remote.origin.url https://xxx.com/repo.git
git branch repo_pr
git fetch origin refs/pull-requests/1/from:repo_pr
git checkout repo_pr
Deepak Govindram Kumbhar July 19, 2019

Guys, any update on this? None of the answers worked for me :(

Getting same error as @Chi Fung Wong

cristianghita24 November 7, 2019

Still not working

cristianghita24 November 7, 2019

wrong comment, cant delete

2 votes
stephan_pampel June 16, 2020

I made this workaround in our build pipeline, it queries the api which triggers the ref creation (same happens if you go to the diff page of the PR).

1. curl --request GET --url $PATH_TO_PR_DIFF > /dev/null

2. git fetch origin refs/pull-requests/PR_NUMBER/from

 

This works for me on bitbucket datacenter server 7.1.3., api documentation: https://docs.atlassian.com/bitbucket-server/rest/7.1.3/bitbucket-rest.html

Chad Fox August 18, 2020

Thanks for this!

I still need to figure out how to get it into our pipeline, but it at least helps explain why our pull requests fail their builds.

0 votes
Andrew_Garner October 22, 2019

This is working for me with BitBucket Server v6.4.1

git fetch origin +refs/pull-requests/*/from:refs/remotes/origin/pull-requests/*

Then `git branch -a` shows the branch available to checkout. 

 

Credit to Örjan Sjöholm

cristianghita24 November 7, 2019

$ git fetch origin +refs/pull-requests/4/from:refs/remotes/origin/pull-requests/4
fatal: couldn't find remote ref refs/pull-requests/4/from
fatal: The remote end hung up unexpectedly

Andrew_Garner November 8, 2019

With Bitbucket Cloud this cannot (currently) be done.

Are you using Bitbucket Cloud (ie bitbucket.org) or Bitbucket Server?

To confirm this for yourself, run `git ls-remote` against a repo with open pull requests. If you have open pull requests and do not see entries for refs/pull-requests or similar in the output from git ls-remote then there are no pull request refs exposed for you to clone.

Like # people like this
André Caldas December 9, 2020

What a bummer!!! Why would I use a web interface when I can do it locally??? :-(

Does GitHub support it?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events