Skip to content

Instantly share code, notes, and snippets.

@TheLandolorien
Created August 29, 2018 17:54
Show Gist options
  • Save TheLandolorien/fac0faf0e80d822634248af9a080f2f8 to your computer and use it in GitHub Desktop.
Save TheLandolorien/fac0faf0e80d822634248af9a080f2f8 to your computer and use it in GitHub Desktop.
Pull GitHub PR based on Branch and PR#
#!/bin/bash
if [[ "$#" -eq 2 ]]; then
TARGET_BRANCH="$1"
ID="$2"
BRANCH_NAME="PR-${ID}"
git checkout $TARGET_BRANCH
git branch -D $BRANCH_NAME
git fetch upstream pull/$ID/head:$BRANCH_NAME
git checkout $BRANCH_NAME
else
echo "Usage: $0 <TARGET_BRANCH> <ID>"
fi
@TheLandolorien
Copy link
Author

Installation Steps

  1. Download git-pull-pr.sh
  2. Open a terminal and change to the place where the file is downloaded (e.g. cd ~/Downloads)
  3. Make the script executable: chmod +x ./git-pull-pr.sh
  4. Copy the script to your local script directory:
    cp proxy.sh /usr/local/bin/git-pull-pr
  5. [Optional] Add /usr/local/bin to PATH (if not done before)
    1. Edit ~/.bash_profile:
      1. Append /usr/local/bin to the PATH variable by adding /usr/local/bin to the front of the string followed by a colon (:)
        • Example:
          export PATH="<SOME_OTHER_PATH_DIRECTORIES>:$PATH"
          becomes (=>)
          export PATH="/usr/local/bin:<SOME_OTHER_PATH_DIRECTORIES>:$PATH"
        • If there is no export PATH setting, just add the following to the first line of your file:
          export PATH="/usr/local/bin:$PATH"
    2. Re-initial your shell:
      source ~/.bash_profile
  6. Run git-pull-pr <DEV> <PULL_REQUEST_ID> from a git directory to create a new branch PR-<PULL_REQUEST_ID>.

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