Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating pull requests using command line from git bash #1219

Closed
Shreejit05 opened this issue Aug 1, 2016 · 9 comments
Closed

Creating pull requests using command line from git bash #1219

Shreejit05 opened this issue Aug 1, 2016 · 9 comments

Comments

@Shreejit05
Copy link

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.

@mislav
Copy link
Owner

mislav commented Aug 7, 2016

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.

@mislav mislav closed this as completed Aug 7, 2016
@Shreejit05
Copy link
Author

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.

@mislav
Copy link
Owner

mislav commented Aug 11, 2016

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.

@max-lobur
Copy link

max-lobur commented Dec 12, 2017

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}

@laksh95
Copy link

laksh95 commented Mar 5, 2018

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?

@max-lobur
Copy link

max-lobur commented Mar 5, 2018

@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

@mislav
Copy link
Owner

mislav commented Mar 6, 2018

@laksh95 There's no way to athenticate the user to the GitHub API using SSH keys. See #1644 (comment)

@harmnot
Copy link

harmnot commented Feb 4, 2019

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

@mislav
Copy link
Owner

mislav commented Feb 4, 2019

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

Repository owner locked as resolved and limited conversation to collaborators Feb 4, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants