Skip to content

Instantly share code, notes, and snippets.

@ltfschoen
Forked from houjunchen/pr.md
Created October 21, 2017 09:57
Show Gist options
  • Save ltfschoen/1f368ee95abdaf3a0043d9b97d4c5106 to your computer and use it in GitHub Desktop.
Save ltfschoen/1f368ee95abdaf3a0043d9b97d4c5106 to your computer and use it in GitHub Desktop.
Checkout Bitbucket Server pull requests locally

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