16

After pushing a change, I see text like this:

Writing objects: 100% (5/5), 478 bytes | 239.00 KiB/s, done.
Total 5 (delta 4), reused 0 (delta 0)
remote:
remote: Create pull request for my-branch => master-branch
remote:   https://bitbucket.org/my-company/repo/pull-requests/12345

But if I don't make a PR at that time, and the text scrolls out of view, that URL is gone. How can I simply generate or re-view that URL without making a change and committing/pushing again?

Grid Trekkor
  • 1,443
  • 2
  • 14
  • 19

5 Answers5

6

This pull request URL is not a git feature but a message generated by a hook script on the BitBucket server.

On a BitBucket server, you can disable it globally with: How do I disable the remote create pull request message when pushing changes?. On the BitBucket cloud you cannot disable it.

One soultion to obtain this message would be to simulate a git pull with the --dry-run option, such as :

git pull --dry-run 

but if this is not enough to trigger the hook, probably that the only way is to go through the BitBucket web interface.

Ortomala Lokni
  • 56,620
  • 24
  • 188
  • 240
3

I was able to generate the URL using a batch file like this:

@echo off

setlocal 
for /f "tokens=*" %%a in ( 
    'git rev-parse --abbrev-ref HEAD'
) do ( 
    set branch=%%a
    set url=https://bitbucket.org/my-company/repo/pull-requests/new?source=%%a^^^&t=1
) 

echo %url%
endlocal 

It simply grabs the current git branch and puts in a string, then echoes the string.

Grid Trekkor
  • 1,443
  • 2
  • 14
  • 19
  • 1
    You can sophisticate this a little: `alias pr_url="https://bitbucket.org/$(git remote -v | head -n 1 | grep -oP '[\w+_]+\/[\w+_]+')/pull-requests/new?source=$(git branch --show-current)"` – Scott Anderson Jan 07 '22 at 14:26
  • @ScottAnderson: great! Event better: ```alias pr_url="https://bitbucket.org/$COMPANY_NAME/$(basename `git rev-parse --show-toplevel`)$(git remote -v | head -n 1 | grep -oP '[\w+_]+\/[\w+_]+')/pull-requests/new?source=$(git branch --show-current)"``` – TerDale Mar 30 '22 at 09:23
2

The URL you've listed here is for a pull request that already exists - the "View pull request" text is the giveaway there. Existing pull requests have an ID in the URL, which you'll need to specify; if you don't know the ID, then you'll need to get the URL from the GUI (https://bitbucket.org/owner/repo/pull-requests/ is probably the easiest place to find it).

If there isn't already a pull request for your branch, then the "Create pull requests" link that the hook generates is https://bitbucket.org/owner/repo/pull-requests/new?source=branchname&t=1.

Jim Redmond
  • 4,139
  • 1
  • 14
  • 18
1

Bash version:

#!/bin/bash

org="myOrg"
branch=$(git rev-parse --abbrev-ref HEAD)
repo_dir=$(git rev-parse --show-toplevel)
repo=$(basename ${repo_dir})
url="https://bitbucket.org/${org}/${repo}/pull-requests/new?source=${branch}&t=1"

echo $url
Jonathan Baker
  • 164
  • 2
  • 3
1

To create a pull request using a web browser (bitbucket web interface), go to the branch web page of your branch, or the branches page of your bitbucket repo.

Using the example in the question:

remote: Create pull request for my-branch => master-branch
remote:   https://bitbucket.org/my-company/repo/pull-requests/12345

We can go to https://bitbucket.org/my-company/repo/branch/my-branch, there is a "Create pull request" link.

Or we can go to https://bitbucket.org/my-company/repo/branches, there is a column named "Pull request", and for branches that don't have an existing pull request, there is a "create" link.

Fan Zeng
  • 171
  • 5