Created
July 19, 2017 12:22
-
-
Save donatello/3d31a3e92e009db1ea349be009d0528d to your computer and use it in GitHub Desktop.
Github review puller git tool
This file contains hidden or 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 | |
USER=$1 | |
BRANCH=$2 | |
function show_help { | |
echo <<EOF | |
Summary: | |
Checkout a Github user's branch locally for review. | |
Usage: | |
git-ghrw USERNAME BRANCH | |
This script first checks out the master branch, updates it by pulling | |
in `upstream/master`, then creates a new branch there named | |
"USERNAME-BRANCH". | |
Then it pulls in BRANCH from the Github user's fork, i.e. it executes: | |
git pull -q https://github.com/USERNAME/REPO_NAME BRANCH | |
The REPO_NAME is detected from the current directory. | |
EOF | |
} | |
if [ -z $USER ]; then | |
echo "Please provide a GitHub username - changes from their fork will be pulled in" | |
show_help | |
exit 1 | |
fi | |
if [ -z $BRANCH ]; then | |
echo "Please provide the branch of the user to pull in" | |
show_help | |
exit 1 | |
fi | |
set -e | |
GIT_DIR=$(git rev-parse --show-toplevel) | |
REPO_NAME=$(basename $GIT_DIR) | |
LOCAL_BRANCH=${USER}-${BRANCH} | |
cd $GIT_DIR | |
echo "Pulling upstream/master -> master and creating new branch $LOCAL_BRANCH." | |
git checkout -q master && git pull -q upstream master && git checkout -q -B $LOCAL_BRANCH | |
echo "Pulling https://github.com/$USER/$REPO_NAME:$BRANCH" | |
git pull -q https://github.com/$USER/$REPO_NAME $BRANCH |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment