Create/Update a Git pull request from command line?

有些话、适合烂在心里 提交于 2020-12-30 02:26:23

问题


I need to create a git pull-request from the command line, without installing any wrappers or additional software. Is there any way to do so in git? I can't seem to find any official git documentation which supports this.


回答1:


Surprisingly (to a lot of people), pull requests are first-class citizens in the git world and not something invented by GitHub.

Use git request-pull to create an E-Mail text you could send over to someone who should fetch some revisions from a server.

This server could be something very basic like a read-only file share or whatever.

The topic is discussed in-depth in the Git Book: https://git-scm.com/book/ch5-2.html

An example: you forked a repo, introduced a patch off the origin/master branch and publish it on a file share called //myserver/myrepo.git. Then you'd type

git request-pull origin/master //myserver/myrepo.git

Then take the output of the command, paste it into an e-mail and you have your pull-request.




回答2:


Edit:

It seems you want a GitHub pull request, not Git pull request. To see the difference, this answer has a good explanation:

https://stackoverflow.com/a/6235394/245966

There is no such a thing as "pull request" in Git itself. The notion of pull requests was introduced to Git ecosystem by the platforms using Git, such as GitHub or Atlassian Stash.

Since it's not a "native" Git concept, you don't have any Git built-ins to open a GitHub pull request from command line.

There's a https://github.com/github/hub tool that can help you automate common GitHub flows from command line.

Having said that, when it comes to opening GitHub pull request or Atlassian Stash pull request, I wrote some command line tools that you can put in PATH to do that job. They were written for my specific use case, feel free to modify them to your needs and use them.

For GitHub:

  • get https://github.com/jakub-g/dotfiles/blob/master/github.profile#L71-83

For Atlassian Stash:

  • get https://gist.github.com/jakub-g/88aca8a7cb63c731b0c6#file-open-atlassian-stash-pullrequest-sh-L9-10

For them to work, you have to have origin and upstream branches properly configured in your repos. They work in a crude way, by parsing the output of git remote commands to construct proper GitHub/Stash pull request URLs and then open them in the browser.

The shell scripts are also checking additional stuff, like making sure you open the pull request from proper branch etc.

For GitHub, also have a look at

  • https://github.com/jakub-g/dotfiles/blob/master/github.profile#L117-119
  • (first npm install -g underscore)

which can guess the number of the next pull request and put it in the commit message before you push.




回答3:


Bash Script

Take a look at the following article which will help you to create PR from the command line.

Using hub package

  • Install hub package on your machine. Follow this link.
  • Checkout to a new branch:
    git checkout -b your-branch-name
    
  • Commit your changes or create an empty commit:
    git commit --allow-empty -m "Your commit message"
    
  • Push the changes:
    git push --set-upstream origin your-branch-name
    
  • Run the following command to create Pull Request:
    hub pull-request
    



回答4:


May 2020: you can use the GitHub CLI "gh"

See "GitHub CLI allows you to close, reopen, and add metadata to issues and pull requests"

GitHub CLI 0.8 makes working with pull requests and issues from your terminal even simpler. This release includes two primary features:

  • You no longer need to open your issue or pull request in the browser immediately after creating it just to add metadata.
    Now you can add reviewers, labels, assignees, projects, and milestones (as applicable) when creating pull requests and issues.
  • Close and reopen pull requests and issues right from the CLI with gh pr close, gh pr reopen, gh issue close, and gh issue reopen.

See how to upgrade in our README!




回答5:


UPD: It looks like it's true and you can't do it "out of the box". you'll have to install a wrapper. Check this Can you issue pull requests from the command line on GitHub? maybe you can find a solution there.



来源:https://stackoverflow.com/questions/31648748/create-update-a-git-pull-request-from-command-line

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!