1

I have checked out a PR into my local. Now the PR got updated, how do I update the local branch with the latest commit. When I try to do git fetch upstream git pull origin all of them are saying the branch is not present. And that is because it is a PR and not a branch. How do I update my local repo?

  • A pull request in Bitbucket (or GitHub) is a phenomenon specific to the repo, not to Git, and certainly not to the local Git running on your machine. You should be able to update a branch which is in pull request review, and the PR should automatically get updated. If you can't pull or push, maybe there is a problem, but I think it is related to something else. – Tim Biegeleisen Jan 09 '20 at 05:22
  • Does this answer your question? [Checkout bitbucket pull requests locally](https://stackoverflow.com/questions/25967034/checkout-bitbucket-pull-requests-locally) – phd Jan 09 '20 at 13:17
  • https://stackoverflow.com/search?q=%5Bbitbucket%5D+pull+request+locally – phd Jan 09 '20 at 13:17

2 Answers2

0

When you check out a PR locally, you are fetching a branch in a specific namespace:

git fetch origin pull/ID/head:BRANCHNAME
# or
git fetch upstream pull/ID/head:BRANCHNAME

But if you do a git config -l, you will probably see a setting like:

remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*

The refspec associated to your remote fetch branches, not pull/branches.

You would need to add (for GitHub pull requests):

fetch = +refs/pull/*/head:refs/remotes/origin/pr/* 

In order to be able to fetch any pr branch.

For BitBucket pull request:

fetch = +refs/pull-requests/*/from:refs/remotes/upstream/pr/*

(provided BitBucket does refresh its PR branch)

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
0

You can update/pull your checked-out un-merged PR Branch by :

git pull upstream pull/PR-NUMBER/head:LOCAL-PR-BRANCH

example : git pull upstream pull/352/head:pr-352

FYI: How to checkout an unmerged PR:

git fetch upstream pull/352/head:pr-352
git checkout pr-352
  • remote can either be upstream or origin
  • 352 is PR number
  • pr-352 is local branch name into which PR is checked-out
Rachita Nanda
  • 4,509
  • 9
  • 42
  • 66