Skip to content

Instantly share code, notes, and snippets.

@samthor
Last active August 29, 2015 14:08
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 samthor/f0c66f193b0c6eccb207 to your computer and use it in GitHub Desktop.
Save samthor/f0c66f193b0c6eccb207 to your computer and use it in GitHub Desktop.
tool for merging git upstream
#!/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