#!/bin/sh # Fast-forward all local branches that track a remote branch # # Branches with local-only commits are skipped # # Usage: git ff-all set -eu git fetch --all --prune current="$(git branch --show-current)" git for-each-ref --format='%(refname:short) %(upstream:short)' refs/heads/ | while read -r branch upstream; do [ -n "$upstream" ] || continue if [ "$branch" = "$current" ]; then git merge --ff-only "$upstream" 2>/dev/null \ || echo "Skipped $branch (not a fast forward)" continue fi git fetch . "$upstream:$branch" 2>/dev/null \ || echo "Skipped $branch (not a fast forward)" done