Skip to content

Instantly share code, notes, and snippets.

@pugson
Last active November 1, 2023 11:54
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 pugson/df144a8e49af3ddc70b21e5a28e8094b to your computer and use it in GitHub Desktop.
Save pugson/df144a8e49af3ddc70b21e5a28e8094b to your computer and use it in GitHub Desktop.
open repo in the browser and submit PR
alias repo="open `git remote -v | grep fetch | awk '{print $2}' | sed 's/git@/http:\/\//' | sed 's/com:/com\//'`| head -n1"
# Open the Pull Request URL for your current directory's branch (base branch defaults to master)
function openpr() {
github_url=`git remote -v | awk '/fetch/{print $2}' | sed -Ee 's#(git@|git://)#https://#' -e 's@com:@com/@' -e 's%\.git$%%' | awk '/github/'`;
branch_name=`git symbolic-ref HEAD | cut -d"/" -f 3,4`;
pr_url=$github_url"/compare/main..."$branch_name
open $pr_url;
}
# Run git push and then immediately open the Pull Request URL
function gpr() {
git push origin HEAD
if [ $? -eq 0 ]; then
openpr
else
echo 'failed to push commits and open a pull request.';
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment