Search code examples
gitbitbucketatlassian-sourcetree

Fetch and checkout a pull request


I have a private repository in BitBucket.

A team member has read access to this repository and has made a pull request to the main repository.

I want to be able to fetch this repo, so I can see the changes on my computer, without merging those changes yet.

After some time on Google I found:

https://confluence.atlassian.com/bbkb/how-to-locally-fetch-and-checkout-a-pull-request-724402529.html

It says to hover over the new repo and the URL is shown below. However, the URL does not show on my browser. UPDATE: Note that I do not have any permissions to access this repository directly!

Therefore, my question is how can I fetch a repository from a pull request without merging it to my main repo.

Info in how to do this in SourceTree GUI will also be helpful.

Update

Note that git ls-remote origin gives output similar to the following:

$ git ls-remote origin
35xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx2d        HEAD
35xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx2d        refs/heads/master
36xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx        refs/tags/v1.0.0.0
bdxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx        refs/tags/v2.2.0.0
49xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx        refs/tags/v2.2.0.0^{}

Solution

  • You can try

    git fetch origin refs/pull-requests/$PR_NO/from:$LOCAL_BRANCH
    

    but there is an open issue that states it's impossible to do what you want.

    Found at https://stackoverflow.com/a/40948201/7976758. Recommendation there is to download patch for the PR and apply at manually.