3

What is the simplest way to perform a git pull request via CLI. I am tired of going to Bitbucket the whole time to create a pull request manually. Which is quite simple indeed:

  1. Pull requests tab
  2. Create pull request
  3. Select source and destiny branches (edit comments, reviewers, etc)
  4. Confirm

Pretty simple. How can I achieve this behavior through cli? Let's say, in my teams' repository, I want to perform a PR from develop to master branch.

I have been checking documentation and it doesn't seem so obvious. It asks me to choose a starting commit and, in the previous steps I described, I don't even get the chance to choose which commit should the PR start from.

jschnasse
  • 8,526
  • 6
  • 32
  • 72
renatodamas
  • 16,555
  • 8
  • 30
  • 51
  • Have you read the bitbucket docs https://www.atlassian.com/git/tutorials/making-a-pull-request? Seems to cover all your questions to me – Liam Mar 21 '18 at 10:40
  • Yes. "_Mary can create the pull request through her Bitbucket account by navigating to her forked repository and clicking the Pull request button in the top-right corner._". That's what I want to stop doing – renatodamas Mar 21 '18 at 10:48
  • Sorry... I was going to say there's [hub](https://hub.github.com/), but didn't see that you were talking about BitBucket. :-( There's no built-in way to do this in Git (it doesn't know anything about GitHub, BitBucket, etc.), so the only way would be to have a wrapper. I'm not sure if you're using BitBucket server, but if so, the [bitbucket server cli](https://bitbucket.org/atlassian/bitbucket-server-cli) may work for you. – John Szakmeister Mar 21 '18 at 10:59
  • 1
    I tried to apply the changes in your question to my answer as well. Question is now more or less a duplicate of https://stackoverflow.com/questions/8721730/bitbucket-send-a-pull-request-via-command-line or am I missing something? – jschnasse Mar 21 '18 at 13:03
  • have you solved it in the meantime? – jschnasse May 23 '18 at 11:47
  • I have pretty much been using the old fashion way, through the Bitbucket website – renatodamas May 24 '18 at 12:23

3 Answers3

3

You could use a command line tool like curl on the bitbucket rest api. How to create a pull request with HTTP POST is documented here.

Give it a try:

 curl \ 
 -X POST \
 -H "Content-Type: application/json" \
 -u username:password \
  https://bitbucket.org/api/2.0/repositories/account/reponame/pullrequests \
 -d @pullrequest.json

with file pullrequest.json containing

 { 
     "title": "Merge some branches", 
     "description": "stackoverflow example",
     "source": { 
         "branch": { 
            "name": "mybranchToMerge" 
          }, 
          "repository": { 
            "full_name": "account/reponame" 
          } 
     }, 
     "destination": { 
         "branch": { 
             "name": "master" 
          } 
      }, 
      "reviewers": [ { "username": "reviewerUsername" } ], 
      "close_source_branch": false 
}

For more options look here:

Bitbucket: Send a pull request via command line?

More about git request-pull can be found here:

Difference between 'git request-pull' and 'pull request'

jschnasse
  • 8,526
  • 6
  • 32
  • 72
  • He's talking about forking a public repo. This answer alos lacks details and clarity – Liam Mar 21 '18 at 10:42
  • 1
    The question asks how to open a pull request via the git CLI, pushing a branch upstream skips the process altogether. – Matan Shahar Mar 21 '18 at 10:43
  • Not what I want. I don't want to push directly to the `master`. I want to achieve that via pull-request. Cause I want to add reviewers that might approve or not my PR – renatodamas Mar 21 '18 at 10:44
  • So your question is how to do it with the bitbucket API? – jschnasse Mar 21 '18 at 10:47
  • @jschnasse It wasn't, I was checking git request-pull documentation, but if it is easier through API then I am fine with it. The question is in fact how to do it in the easiest way – renatodamas Mar 21 '18 at 11:04
  • You can do it with curl via the REST-API. E.g. create a PR with a POST like documented here: https://docs.atlassian.com/bitbucket-server/rest/4.9.1/bitbucket-rest.html#idp2046528 – jschnasse Mar 21 '18 at 11:07
  • I repeat, your treating this as a private repo (i.e. one your company uses) not a open source public repo with contributors. He wants to **fork** not just push and pull some changes – Liam Mar 21 '18 at 11:11
  • [Just read this](https://www.atlassian.com/git/tutorials/making-a-pull-request) this is basically what the OP wants... – Liam Mar 21 '18 at 11:12
  • 1
    @Liam - No the OP wants to make a PR over command line. See question. Please revert downvote. – jschnasse Apr 06 '18 at 12:16
1

Probably the answer to your question is disappointing, as Pull Requests are not a native feature of git they are not supported through the CLI or any other standard git tool. Additionally there is no standard protocol for Pull Requests even outside of standard git. Each platform (GitLab, GitHub etc.) provides its own flavor of Pull Requests.

Since you question is about Pull Requests in general and not about Pull Requests on a specific provider the answer is that it cannot be done.

Matan Shahar
  • 3,190
  • 2
  • 20
  • 45
0

If you are using bitbucket enterprise, i prepared a script to create/delete pull requests - https://github.com/psadi/bbcli.

It also handles adding of default reviewers automatically to your PR which is configured in your repo settings.

psadi
  • 149
  • 7
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/late-answers/30868965) – Simas Joneliunas Jan 25 '22 at 13:07