Skip to content

Instantly share code, notes, and snippets.

@gmassanek
Created March 23, 2012 01:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gmassanek/2166057 to your computer and use it in GitHub Desktop.
Save gmassanek/2166057 to your computer and use it in GitHub Desktop.
Alias to push and open chrome to the new pull request page
function git_remote_url() {
# DOES NOT WORK FOR HTTPS, ONLY git@github.com:username/repo.git
git config --get remote.origin.url | sed 's/git@//' | sed 's/github/https:\/\/github/' | sed 's/com:/com\//' | sed 's/\.git//'
}
function git_current_branch_name() {
git symbolic-ref HEAD | sed 's/refs\/heads\///'
}
function git_push_open() {
branch_name=$1
if [ -z $branch_name ]; then
branch_name=`git_current_branch_name`
fi
git_repo_url=`git_remote_url`
pull_path="/pull/new/"
$new_pull_request_url=$git_repo_url$pull_path$branch_name
echo $new_pull_request_url
git push origin HEAD:$branch_name && open $new_pull_request_url
}
alias gpush="git_push_open"
@gmassanek
Copy link
Author

Also one of my favorites. alias gprom="git pull --rebase origin master"

@gmassanek
Copy link
Author

This requires you to run git config host.url https://github.com/username/repo

function git_remote_url() {
# DOES NOT WORK FOR HTTPS, ONLY git@github.com:username/repo.git
  git config --get remote.origin.url | sed 's/git@//' | sed 's/github/https:\/\/github/' | sed 's/com:/com\//' | sed 's/\.git//'
}

function configured_url() {
  git config --get host.url
}

function git_current_branch_name() {
  git symbolic-ref HEAD | sed 's/refs\/heads\///'
}

function git_push_open() {
  branch_name=$1
  if [ -z $branch_name ]; then
    branch_name=`git_current_branch_name`
  fi

  git_repo_url=`configured_url`
  if [ -z $branch_name ]; then
    git_repo_url=`git_remote_url`
  fi
  pull_path="/pull/new/"
  echo "Pushing HEAD to "$branch_name
  echo "Click Open Pull Request on "$git_repo_url$pull_path$branch_name
  git push origin HEAD:$branch_name && open $git_repo_url$pull_path$branch_name
}
alias gpush="git_push_open"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment