Last active
June 15, 2018 15:45
-
-
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.
This file contains hidden or 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
# 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