Local checkout of a pull request in Stash

I couldn't find a way to checkout locally a pull request in Stash.

Let's say that Dev1 created a pull request for Dev2. How is Dev2 supposed to try that code locally before approving/rejecting that pull request?

In a Github-like scenario, Dev2 would create a local branch related to that pull request...
It seems that it's not possible to do the same thing in Stash?

Thanks in advance,

3 answers

1 accepted

Hi Charles,

I know I could add the other repo as a remote, but it has some drawbacks:

  • 1. using the current UI you can't get the from url easily, but you have to:
    • - remember the structure .../scm/~user/repo.git
    • - or
      • -- click on the PR author's name
      • -- track down her repo
      • -- click on "Clone"
    • - add the remote
    • - and then you also have to checkout the correct branch ;)
  • 2. with several forks you also have to deal with a growing remote list

However, your "worst case" appears to be my ideal solution...
I've just created an alias:

  prstash = "!f() { git fetch $1 refs/pull-requests/$2/from:$3; } ; f"

and now I can just type:

git prstash origin 3 dest-branch

to checkout the 3rd pull request onto dest-branch!


I got this working but I had a question, is there a way to update the branch when the person making the pull request makes an update to the request?

I guess you can just run the same command again to fetch updates?

Hi Stefano,

The workflow for checking out a local PR should be identical to using GitHub. If the pull request is between branches in a single repository, you can just checkout (create a local branch) of their source. If you're using a forking workflow, you will need to add their personal repository as a Git 'remote' and then checkout.

Or is the problem that you don't have access to their repository? On our team we normally add permissions to their forked repository to our teams group so we can fetch from them in these scenarios.

In the worst case, where someone may not be around to update their permissions (or chooses not to) you can run the following to get access to the 'from' branch of any pull request:

git fetch origin refs/pull-requests/$PR_NO/from:$LOCAL_BRANCH

Where $PR_NO is the number of your pull request.



Is this something that can be added into the helper text in Stash Pull Request view, to enable teams an easier job to pull down pull requests locally and run whatever tests and other things before approving the merge? This would REALLY be helpful for a large organization setting, where teams don't constantly flip permissions back and forth for all the pull requests from forks.

This is an example of how it is done in Gitorious:

One way to merge in these changes is to pull them into a local branch for review, verifying the changes and then merge to back to master.

# Check out a new branch for integration
git checkout -b merge-requests/8

# Fetch the merge request into this branch
git pull \
  git://git.orbitz.net/continuous-delivery/jenkins-jobdsl.git \

# Show the commits, assess they are okay
git log --pretty=oneline --abbrev-commit next..merge-requests/8

Hi Alex,

I'm afraid we don't really want to publicly advertise the (internal) pull-requests ref. It's an internal implementation detail that just happens to be usable from Git if you know how.

There are a few options, depending on the use-cases we need to support. I've created a feature request which you might want to follow and vote on. If you would be so kind as to document your workflow on the issue with a commen as well that would be most kind.




Hello Charles,

I've added the description of the possible flow to the Jira you've provided.

I've also opened another Jira - https://jira.atlassian.com/browse/STASH-3623, so you might want to link them together.


Thanks Alex. I've closed your issue as a duplicate to make it easier to track.

Hi Guys, I'm in a similar situation, where I am reviewing a PR from a fork that I don't have permissions to view/clone. I've tried using your internal API as a temporary workaround, but that no longer seems to work. I also looked at the Jira referenced here, but that doesn't seem to have made any progress. Any suggestions?

Hi Graham,

How do you mean no longer works? If you run 'git ls-remote' what do you see? At a previous version of Stash (I can't remember which) Stash no longer kept the refs for merged/rejected PRs, but other than that it should still as normal/expected.



Huh, I guess I can see it in the remotes, but when I tried to fetch it, I get

fatal: 'refs/pull-requests/6/from' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights and the repository exists.

Hi Graham,

Looks like you're using the wrong command. It should be something like:

git fetch origin refs/pull-requests/6/from:local_name

I suspect you're leaving off the the 'origin' part.

EDIT: Whoops, looks like I started it with the incorrect command in my answer. I'll fix that now.



Ah yes, that was exactly it. Thanks a lot :) Added a vote to the Jira issue as well, hopefully something to enable this will be added at some point.

I created a bookmarklet that does this 


javascript:(function()%7Bbranch %3D jQuery('.ref.branch .name%3Afirst').text()%3Bref %3D 'refs%2Fheads%2F' %2B branch%3Bref %3D encodeURIComponent(ref)%3Busername %3D jQuery('%23current-user').attr('data-username')%3BsourceTreeLink %3D jQuery('%23sourcetree-clone-button').attr('href')%3Blocation.href %3D sourceTreeLink.replace('cloneRepo%3F'%2C'checkoutRef%3Fref%3D' %2B ref %2B '%26')%7D)()

Suggest an answer

Log in or Register to answer