Normally we use GIT UI to create the pull request from master to any branch or vice versa.
if there are many branches it takes so-much time to create pull request for each and every branch.
Are there any script or commands to create the pull request from GIT bash for multiple branches.
Yes you can make a bash script like:
pr() {
git push -u origin "$1"
hub pull-request -h "$1" -F -
}
pr "my-branch1" <<MSG
This is a pull request title for my-branch1
This is a description of my pull request. Markdown body goes here.
MSG
pr "my-branch2" <<MSG
This is a pull request title for another branch
This is another description for my second pull request.
MSG
# ....
Repeat for however many branches you have. In short, hub definitely allows you to automate opening pull requests from the command-line, but it's up to you to make the implementation.
Thanks for your reply. I have tried with the above code but I am getting the error as (hub: command not found)
And also you have mentioned" it allows you to automate opening pull requests". Did you mean I can open an existing pull request for the same branch or I can create a pull request for the same.
Oh, I'm sorry. I thought that you opened an issue on this repository because you were already a user of hub
. This project is about developing a command-line tool called hub
that wraps git and allows you to write scripts from the command line to automate tasks like forking or opening pull requests. My script above will start working for you after you install hub. The instructions are available on our README.
https://github.com/max-lobur/dotfiles/blob/master/sh/pull_req.sh :
#!/usr/bin/env bash
#
# To make it work:
# brew install hub
# hub browse
#
# and git remotes:
# "origin" - your fork
# "upstream" - upstream-org/repo-name
#
UPSTREAM=upstream-org/repo-name:master
echo -n "Pull Request Title: "
read title
topic_branch=`git rev-parse --abbrev-ref HEAD`
git push origin ${topic_branch}
hub pull-request -b ${UPSTREAM} -F - > /tmp/last_pr_url <<MSG
${title}
`cat PULL_REQUEST_TEMPLATE`
MSG
pr_url=`cat /tmp/last_pr_url`
echo "Opening ${pr_url}"
open ${pr_url}
I am having trouble while using the solution given by @mislav So I have added the function you mentioned and it seems to work because it asked for my github username, password and 2FA code. Now is there a way all these steps can be skipped? I mean is there a way to authorize the user using the ssh keys?
@laksh95
hub browse
@laksh95 There's no way to athenticate the user to the GitHub API using SSH keys. See https://github.com/github/hub/issues/1644#issuecomment-359002547
@max-lobur what is the first step I should create for create full request by command with hub ? and what command after create that function ??
@harmnot To create a pull request using hub:
hub pull-request -p
. See https://hub.github.com/hub-pull-request.1.html for more information.
Most helpful comment
Yes you can make a bash script like:
Repeat for however many branches you have. In short, hub definitely allows you to automate opening pull requests from the command-line, but it's up to you to make the implementation.