It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How do I create a pull request from the command line?

Øyvind Harboe Sep 26, 2016

With Gerrit I type "git push origin HEAD:refs/for/master", what's the equivalent for bitbucket?

4 answers

2 votes
Laurent Boivin Sep 27, 2016

If you want to create a Pull Request from the command line, you can use the REST API :

curl -s -u USER:PASSWD -X POST -H 'Content-Type: application/json' -d 'JSON_struct_with_data' http://SERVER:PORT/rest/api/1.0/projects/PRJKEY/repos/REPONAME/pull-requests

Check the doc of REST API for the details on the JSON data block.



Øyvind Harboe Sep 27, 2016

Ouch! I get a lot of groans about the the arcane Gerrit syntax (git push origin HEAD:refs/for/MAIN) and the above is not an improvement.

I was hoping that there was something no more complicated in terms of syntax, configurations, required tools to be installed, passwords, etc. than Gerrit for creating a Bitbucket pull requests.

Tim Crall Sep 28, 2016

There is - the web UI...

Øyvind Harboe Sep 28, 2016

I'm up against Gerrit, compared to Gerrit that's just one additional step to get wrong:


  1. Create branch
  2. Go to GUI create pull request


Instead of:

git push origin HEAD:refs/for/master


=> done!



Nathan Phillip Brink Jun 17, 2018

At least you could write a custom script since there’s a REST API. So this is better than nothing.

Øyvind Harboe Sep 27, 2016

I can't see anything in that link that shows me how to create a pull request from the command line. I have created pull requests in the Bitbucket web-interface, I've downloaded pull requests from the command line, but I've never found a way to create pull requests from the command line.

Like Alexandre Harada likes this
Nam VU Oct 27, 2018

Jonas may drop the part "command line"

Jaume Mila Bea I'm New Here Apr 09, 2019

Jonas dropped everything but "pull".

0 votes
dragon788 May 10, 2017

The best option is probably to use a couple different tools developed for Stash and/or BItBucket Cloud to do this. The REST API should be similar between them (even though their codebases aren't necessarily the same).

See the excellent utilities I came across from this StackOverflow answer.

the Attlassian team have stash (ruby):

Zhemao has bitbucket-cli (python):


Israel Tsadok Nov 15, 2017

You have a broken link: stash is now at

dragon788 Jun 07, 2018

Good spot. It is also easy to install them via `gem install atlassian-stash`. Once you've run `stash configure` you can easily operate on a large number of repos in a loop if you are dealing with a massive find/replace for example.

Sadly it only operates on https remote-url configured repos even though it should be able to map ssh:// or git repos to the SSH counterpart since the `stash configure` requires the web URL and the repo URL should largely match.

Given a local folder like PROJECTNAME if you are updating a duplicated entry across multiple repositories you can `cd PROJECTNAME` and then run the script below (assuming you setup the `git create-pull-request` alias.

for repo in `ls -A`; do 
pushd $repo;
git remote set-url origin https://stash.internal:8444/scm/PROJECTNAME/$(basename $(pwd)).git ;
git create-pull-request branches/JIRA-123 master @reviewer1 @reviewer2 ;
git remote set-url origin ssh://git@stash.internal:7999/PROJECTNAME/$(basename $(pwd)).git;
popd 2>&1 >/dev/null ;
Raviteja Badisa Jul 18, 2018

Is there any other way we can perform this action without having stash installed?

Simon Storr Mar 27, 2019

I would be keen to find this out. We have 27 repositories which need e.g. their AssemblyInfo.cs updating with the new major version number so would like to automate creating pull requests for all these in one go - the UI takes far too long :/

Like Matthias Fischer likes this
0 votes
Robert Szalai I'm New Here Apr 04, 2019 • edited



I am getting this:

/var/lib/gems/2.5.0/gems/commander-4.1.6/lib/commander/user_interaction.rb:328: warning: constant ::NIL is deprecated
/var/lib/gems/2.5.0/gems/commander-4.1.6/lib/commander/user_interaction.rb:328: warning: constant ::Data is deprecated
/var/lib/gems/2.5.0/gems/commander-4.1.6/lib/commander/user_interaction.rb:328: warning: constant ::TRUE is deprecated
/var/lib/gems/2.5.0/gems/commander-4.1.6/lib/commander/user_interaction.rb:328: warning: constant ::FALSE is deprecated
/var/lib/gems/2.5.0/gems/commander-4.1.6/lib/commander/user_interaction.rb:328: warning: constant ::Fixnum is deprecated
/var/lib/gems/2.5.0/gems/commander-4.1.6/lib/commander/user_interaction.rb:328: warning: constant ::Bignum is deprecated
/var/lib/gems/2.5.0/gems/commander-4.1.6/lib/commander/user_interaction.rb:328: warning: constant ::TimeoutError is deprecated
Traceback (most recent call last):
11: from /var/lib/gems/2.5.0/gems/commander-4.1.6/lib/commander/import.rb:10:in `block in <top (required)>'
10: from /var/lib/gems/2.5.0/gems/commander-4.1.6/lib/commander/delegates.rb:8:in `run!'
9: from /var/lib/gems/2.5.0/gems/commander-4.1.6/lib/commander/runner.rb:82:in `run!'
8: from /var/lib/gems/2.5.0/gems/commander-4.1.6/lib/commander/runner.rb:422:in `run_active_command'
7: from /var/lib/gems/2.5.0/gems/commander-4.1.6/lib/commander/command.rb:155:in `run'
6: from /var/lib/gems/2.5.0/gems/commander-4.1.6/lib/commander/command.rb:180:in `call'
5: from /var/lib/gems/2.5.0/gems/atlassian-stash-0.7.0/bin/stash:142:in `block (2 levels) in <top (required)>'
4: from /var/lib/gems/2.5.0/gems/atlassian-stash-0.7.0/lib/atlassian/stash/git.rb:50:in `ensure_within_git!'
3: from /var/lib/gems/2.5.0/gems/atlassian-stash-0.7.0/bin/stash:144:in `block (3 levels) in <top (required)>'
2: from /var/lib/gems/2.5.0/gems/atlassian-stash-0.7.0/lib/atlassian/stash/pull_request.rb:101:in `create_pull_request'
1: from /usr/lib/ruby/2.5.0/json/common.rb:156:in `parse'
/usr/lib/ruby/2.5.0/json/common.rb:156:in `parse': 765: unexpected token at '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> (JSON::ParserError)
<title>302 Found</title>
<p>The document has moved <a href="https://bitbucket...">here</a>.</p>


Any idea how to resolve it?



Laurent Boivin Apr 04, 2019


You are calling an URL that redirects to another one for some (hopefully good) reason.

The library you are using is not handling this redirect automatically and you get the response "302 - what you are looking for is not here, but it's there".

So you should either find the option in the library you are using to follow the redirection when it occurs, or you must check first your HTTP response code before processing the HTTP response message.

On HTTP code 302, you should call the new URL.


Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published in Bitbucket Pipelines

Building a Bitbucket Pipe as a casual coder :  #!/bin/bash source "$(dirname "$0")/" enable_debug extra_args="" if [[ "${DEBUG}" == "true" ]]; then extra_args="--verbose" fi # mandatory variables R...

1,734 views 1 18
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you