bin/git-upstream-sync
#!/usr/bin/env bash
#
# Author: Joe Block <jpb@unixorn.net>
# License: Apache 2.0
# https://github.com/unixorn/git-extra-commands/blob/master/LICENSE
#
# Sync to upstream/yourforkname and rebase into your local fork. then push
# back into yourfork/yourforkname
#
# Assumes that your upstream fork's remote is named upstream unless you
# set upstream-sync.remote with git config
branch_name=$(git symbolic-ref --short -q HEAD)
upstream_remote=$(git config --get upstream-sync.remote)
# shellcheck disable=SC2181
if [[ $? != 0 ]]; then
echo 'Using default remote of upstream'
upstream_remote='upstream'
fi
git fetch "${upstream_remote}" && \
git rebase "${upstream_remote}/${branch_name}" && \
git push && \
git fetch -p