Locate the section for your stash remote in the .git/config
file. It looks like this:
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
url = [email protected]:private/repository.git
Now add the line fetch = +refs/pull-requests/*:refs/remotes/origin/pull-requests/*
to this section. Obviously, change the stash url to match your project's URL. It ends up looking like this:
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
url = [email protected]:private/repository.git
fetch = +refs/pull-requests/*:refs/remotes/origin/pull-requests/*
Now fetch all the pull requests:
$ git fetch origin
From stash.internal:private/repository
* [new ref] refs/pull-requests/1000/from -> origin/pull-requests/1000
* [new ref] refs/pull-requests/1001/from -> origin/pull-requests/1001
* [new ref] refs/pull-requests/1002/from -> origin/pull-requests/1002
* [new ref] refs/pull-requests/1003/from -> origin/pull-requests/1003
...
To check out a particular pull request:
$ git checkout pull-requests/1000/from
Branch pull-requests/1000/from set up to track remote branch pull-requests/1000/from from origin.
Switched to a new branch 'pull-requests/1000/from'
I'm able to create a branch from the fetched pull request this way, but you still need to know the pull request id:
Where 2 is the pull-request id from the URL
https://myStashURL/projects/PROJECT_NAME/repos/REPO/pull-requests/2/overview
I can still update the .git/config (as above) but it's unneeded if you know the id of the pull request (say from an email notification).
Also; here's the one-liner I use to update the .git/config as needed:
git config --add remote.origin.fetch '+refs/pull-requests/:refs/remotes/origin/pull-requests/'