Skip to content

Instantly share code, notes, and snippets.

@DmitriyRF
Last active August 5, 2019 15:11
Show Gist options
  • Save DmitriyRF/73278cb02894c63ae175b3e973109891 to your computer and use it in GitHub Desktop.
Save DmitriyRF/73278cb02894c63ae175b3e973109891 to your computer and use it in GitHub Desktop.
How to fetch/checkout/pull remote pull/merge-request to local repository

Locate the section for your Bitbucket Server remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = git@<your repo url>

Now add the line fetch = +refs/pull-requests/*/from:refs/remotes/origin/pull-requests/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = git@<your repo url>
	fetch = +refs/pull-requests/*/from:refs/remotes/origin/pull-requests/*

Now fetch all the pull requests:

$ git fetch origin
From <your repo url>
 * [new ref]         refs/pull-requests/1000/from -> origin/pull-requests/1000
 * [new ref]         refs/pull-requests/1002/from -> origin/pull-requests/1002
 * [new ref]         refs/pull-requests/1004/from -> origin/pull-requests/1004
 * [new ref]         refs/pull-requests/1009/from -> origin/pull-requests/1009
...

To check out a particular pull request:

$ git checkout pull-requests/999
Branch pull-requests/999 set up to track remote branch pull-requests/999/from from origin.
Switched to a new branch 'pull-requests/999'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment