Last active
August 29, 2015 14:08
-
-
Save samthor/f0c66f193b0c6eccb207 to your computer and use it in GitHub Desktop.
tool for merging git upstream
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 | |
git status 1>/dev/null || exit 1 | |
git fetch upstream | |
if [ "$?" != "0" ]; then | |
echo >&2 | |
echo "fatal: no upstream remote configured" >&2 | |
ORIGIN=$(git remote -v | grep ^origin | cut -f2 | cut -f1 -d' ' | head -n 1) | |
if [[ "$ORIGIN" =~ ^git@github\.com:(.*)/(.*)$ ]]; then | |
REPO="${BASH_REMATCH[2]}" | |
# nb. this uses https:// explicitly rather than git | |
echo " git remote add upstream https://github.com/OWNER/${REPO}" >&2 | |
fi | |
exit 1 | |
fi | |
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) | |
BRANCH="${1-$CURRENT_BRANCH}" | |
echo "merge: upstream/${BRANCH}" | |
git merge upstream/$BRANCH | |
if [ "$?" != "0" ]; then | |
BASE=$(basename $0) | |
echo " use: $BASE branch_name" >&2 | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment