Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create pull request from command line?

When I'm done with my work, I add, commit and push the changes to the remote branch tracked by the curernt one. So the commands are as follows.

checkout donkey
add .
commit --message
push

Now, I'd like to create a pull request. It doesn't matter to me if I request the pull from my local donkey or the remote one. I cna do that using GUI but it's more like-a-bossy to perform that operation using CLI, in my opinion.

According to this article, I'm supposed to run something like this.

git request-pull donkey remote/donkey

or perhaps

git request-pull remote/donkey remote/dev

However, after trying several different combinations, I've failed, only obtaining a series of errors implying that the command is correct but the parameters make no sense.

Strangely, there's not much about creating pull requests to be found when googling, possibly drowning in the info using GUI.

like image 427
Konrad Viltersten Avatar asked Feb 24 '20 09:02

Konrad Viltersten


2 Answers

A pull request is a thing that GitHub, or Bitbucket, or some other web hosting service, provides. It is not part of Git itself.

The git request-pull command generates email messages. If email messages are the (or a) mechanism your hosting provider gives you to make a pull request, this could work. However, the actual mechanisms that GitHub and Bitbucket and other providers use is not email-based, so this does not do any good.

Kevin Siahaan's answer (deleted since I started typing this) provides links to some CLI tools for manipulating GitHub without using a browser. This adds a set of additional commands, not part of Git itself but usable via the git front end. Maroun's comment has a link to another GitHub-specific CLI. But this only works with GitHub. You're using Bitbucket.

See ElpieKay's comment for some additional Bitbucket-specific links.

Note that if you write your own tool—in any language you like; Python might be a good one since the requests library makes it very easy to call REST-server operations, though Go is also nice for wrapping web operations—you can place the executable image anywhere in your $PATH, name it (e.g.) git-xyzzy, and invoke it as git xyzzy. There are some minor limitations to extending Git like this: in particular git help xyzzy generally won't work unless you've installed manual-page documentation in whatever way your system provides manual-page documentation. But it is pretty useful for writing new custom commands.

like image 142
torek Avatar answered Sep 26 '22 20:09

torek


I'm going to pull @Maroun's comment up into an answer for visibility. GitHub has an officially released solution for creating pull requests from the command line: the GitHub CLI.

My way of using this was to create a Personal Access Token and pass that to gh auth to log into my company's GitHub Enterprise site, then create the PR:

gh auth login --hostname github.my_company.com --with-token < my_token.txt
gh pr create --title "Pull request title" --body "Pull request body"
like image 21
Noumenon Avatar answered Sep 26 '22 20:09

Noumenon