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

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

3 answers

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.



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.

There is - the web UI...

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!



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

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 1 person likes this

Jonas may drop the part "command line"

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):


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 ;

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

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 06, 2018 in Bitbucket

Upgrade Best Practices

Hello! My name is Mark Askew and I am a Premier Support Engineer for products Bitbucket Server/Data Center, Fisheye & Crucible. Today, I want to bring the discussion that Jennifer, Matt, and ...

655 views 5 9
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you