Skip to content

Instantly share code, notes, and snippets.

@suzuki-shunsuke
Last active September 20, 2019 12:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save suzuki-shunsuke/f7033be1bcec54bc67b10a7da50d5ee8 to your computer and use it in GitHub Desktop.
Save suzuki-shunsuke/f7033be1bcec54bc67b10a7da50d5ee8 to your computer and use it in GitHub Desktop.
The shell function to create a pull request from the current feature branch.
send-pr() {
local remote=`git config branch.master.remote`
local remote_url=`git config remote.${remote}.url`
case "$remote_url" in
https://github.com*)
git-pr
;;
https://ghe.example.com*)
ghe-pr
;;
*)
echo "unexpected remote_url: $remote_url" >&2
return 1
;;
esac
}
ghe-pr() {
GIT_USERNAME=<your github user name> \
GITHUB_TOKEN=<your github personal access token> \
GITHUB_HOST=ghe.example.com \
_git-pr
}
git-pr() {
GIT_USERNAME=<your github user name> \
GITHUB_TOKEN=<your github personal access token> \
_git-pr
}
_git-pr() {
local branch=`git-current-branch`
if [ "$branch" = "" ]; then
echo "failed to get the current branch" >&2
return 1
fi
git push origin $branch || return 1
hub pull-request -o -h $GIT_USERNAME:$branch
}
git-current-branch() {
git branch | grep "^\* " | sed -e "s/^\* \(.*\)/\1/"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment