Hub: Creating pull requests using command line from git bash

Created on 1 Aug 2016  路  9Comments  路  Source: github/hub

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.

Most helpful comment

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.

All 9 comments

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

  1. hub browse
  2. pass username, 2FA and so-on
  3. Make sure it works
  4. Use other hub commands (and functions) without prompts - the auth is now cached

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

  1. Create a new git branch;
  2. Make some commits in that branch;
  3. Use hub pull-request -p. See https://hub.github.com/hub-pull-request.1.html for more information.
Was this page helpful?
0 / 5 - 0 ratings

Related issues

Kristinita picture Kristinita  路  4Comments

kentcdodds picture kentcdodds  路  4Comments

ssbarnea picture ssbarnea  路  3Comments

kurko picture kurko  路  4Comments

wwwdata picture wwwdata  路  3Comments