Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
An example script to show how to fetch from all default remotes and do any fast-forwards of local branches from upstream possible
#!/bin/sh
set -e
CURRENT_BRANCH="$(git symbolic-ref HEAD)"
CURRENT_BRANCH_UPSTREAM="$(git rev-parse --symbolic-full-name @{u} 2> /dev/null)"
# Update the remote-tracking branches for every remote for which
# remote.<name>.skipDefaultUpdate is not true:
git remote update default
git for-each-ref --shell --format="REF=%(refname); UPSTREAM=%(upstream)" \
refs/heads | while read entry
do
eval "$entry"
echo "Considering $REF ..."
# Deal with the current branch last:
if [ "$REF" = "$CURRENT_BRANCH" ]
then
echo " Skipping the current branch for now."
continue
fi
if [ x"$UPSTREAM" = x ]
then
echo " No upstream branch is set for $REF"
continue
fi
REF_HASH="$(git rev-parse --verify $REF)"
UPSTREAM_HASH="$(git rev-parse --verify $UPSTREAM)"
MERGE_BASES="$(git merge-base $REF $UPSTREAM)"
if [ x"$REF_HASH" = x"$UPSTREAM_HASH" ]
then
echo " The branch is already at the upstream version"
continue
fi
# Now test if the branch can be fast-forwarded:
if [ x"$MERGE_BASES" = x"$REF_HASH" ]
then
echo " Fast-forwarding $REF from $UPSTREAM"
echo " $REF_HASH -> $UPSTREAM_HASH"
git update-ref "$REF" "$UPSTREAM_HASH"
else
echo " Cannot fast-forward $REF with $UPSTREAM"
fi
done
if [ x"$CURRENT_BRANCH_UPSTREAM" = x ]
then
echo "No upstream branch was found for the current branch ($CURRENT_BRANCH)"
else
echo "Now deal with the current branch:"
echo "While on $CURRENT_BRANCH, merging from $CURRENT_BRANCH_UPSTREAM"
git merge $CURRENT_BRANCH_UPSTREAM
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.