Last active
January 16, 2023 05:16
-
-
Save innocarpe/8bef184fbcf14f4788f27a28ad0701cf to your computer and use it in GitHub Desktop.
'git push && create a pull request command' for Github
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This will push current branch to origin and open a 'Create a pull request' page for Github. | |
# | |
# 1. Move this file to ~/.gitsh/ | |
# 2. Add directory path($YOUR_HOME_PATH/.gitsh) to environment variable file | |
# (like ~/.bash_profile or ~/.zshrc) | |
# 3. chmod 0755 git-pr | |
# 4. Use the command 'git pr' | |
BRANCH=$(git branch --list | awk '{ if ($1 == "*") print $2 }'d) | |
REMOTE_ORIGIN=$(git remote get-url --push origin) # git@github.com-SSH_ID:ORGANIZATION/REPO_NAME.git | |
_REPO_PATH=${REMOTE_ORIGIN%.git} | |
REPO_PATH=${_REPO_PATH#*:} | |
PR_URL="https://github.com/$REPO_PATH/pull/new/$BRANCH" | |
# PR_URL="https://github.com/YOUR_ORGANIZATION/YOUR_REPO/pull/new/$BRANCH" # Use this when you doesn't use SSH but HTTPS | |
echo -e "PR_URL: ${PR_URL}" | |
PUSH_COMMAND="git push origin $BRANCH" | |
echo -e "Executing '$PUSH_COMMAND'" | |
$PUSH_COMMAND | |
CREATE_PR_COMMAND="open $PR_URL" | |
echo -e "Create a pull request for '$BRANCH'" | |
$CREATE_PR_COMMAND | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment