Skip to content

Instantly share code, notes, and snippets.

@jasonkeene
Last active June 15, 2018 15:45
Show Gist options
  • Save jasonkeene/9640939 to your computer and use it in GitHub Desktop.
Save jasonkeene/9640939 to your computer and use it in GitHub Desktop.
Automatically fetch remotes then fast forward to the new changes or launch a GUI.
# first update all remote branches
git fetch --all --prune
# loop over all local/remote pairs
git for-each-ref --format="%(refname:short) %(upstream:short)" refs/heads | \
while read local remote
do
# make sure remote exists
[ -z "$remote" ] && continue
# see if there is a difference between the two
if [ -n "$(git rev-list --left-right ${local}..${remote})" ]
then
# if there is attempt a fast forward merge
git checkout $local
git merge --ff-only $remote
fi
# finally if the ff-merge failed launch a gui to view the branches
if [ -n "$(git rev-list --left-right ${local}..${remote})" ]
then
$(which gitx || which gitg || which gitk || which git gui)
continue
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment