Skip to content

Instantly share code, notes, and snippets.

@orjan
Last active August 7, 2020 21:40
Show Gist options
  • Save orjan/677255b4acec610e3dfd02c7a2431d95 to your computer and use it in GitHub Desktop.
Save orjan/677255b4acec610e3dfd02c7a2431d95 to your computer and use it in GitHub Desktop.
Checkout pull request in Bitbucket server

Checking out pull requests in Bitbucket

/.git/config
[remote "origin"]
    url = ssh://git@git.dev.viaeuropa.int:7999/brikks/brikks.git
    fetch = +refs/heads/*:refs/remotes/origin/*
    fetch = +refs/pull-requests/*/from:refs/remotes/origin/pull-requests/*
    fetch = +refs/pull-requests/*/merge:refs/remotes/origin/pull-requests-merge/*

Every now or then I find myself looking for a way to checkout a pull request on my computer, a cool thing is that they are available directly from stash, I'll focus on stash here but github will work in a similar way. By adding:

fetch = +refs/pull-requests/*/from:refs/remotes/origin/pull-requests/*

you'll be will be able to checkout any pull request by writing git checkout pull-request/1337

What about merging?

When we hit the merge button stash we'll merge the pull request to a target branch e.g. develop, master the problem is that it's possible that the merged code won't build e.g. if another branch sneaks in before and change a method name. By adding:

fetch = +refs/pull-requests/*/merge:refs/remotes/origin/pull-requests-merge/*

you'll be able to see how the result would look like after the merge to develop.

CI

I'm also writing this part since I struggling with feature branches vs pull requests. They are pretty much the same but our feature branches are living in the same repo as master and develop and build directly from start. Puil requests on the other hand can be located everywhere making it possible to rewrite the history for the pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment