Skip to content

Instantly share code, notes, and snippets.

@houjunchen
Forked from piscisaureus/pr.md
Last active February 14, 2023 14:31
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save houjunchen/179766d70068a8cf02f50cdab099cfa3 to your computer and use it in GitHub Desktop.
Save houjunchen/179766d70068a8cf02f50cdab099cfa3 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