Skip to content

Instantly share code, notes, and snippets.

@crucialfelix
Last active June 22, 2023 11:43
Show Gist options
  • Save crucialfelix/73e1cd0621d689a15c34fced4c2c9e5d to your computer and use it in GitHub Desktop.
Save crucialfelix/73e1cd0621d689a15c34fced4c2c9e5d to your computer and use it in GitHub Desktop.
git force push all feature branches
#!/bin/bash
set -e
# Iterate over all local branches matching feat/
for branch in $(git branch); do
# Skip branches that do not match the feat/* pattern
if [[ ! "$branch" =~ ^feat/.* ]]; then
continue
fi
echo "Branch: $branch"
# Check if there is an upstream configured for the branch
if ! git rev-parse --abbrev-ref --symbolic-full-name "$branch"@{upstream} > /dev/null 2>&1; then
echo "Error: No upstream configured for branch $branch."
continue
fi
git checkout "$branch"
if git status -uno | grep -q 'Your branch is up to date'; then
up_to_date=1
else
up_to_date=0
fi
if [ "$up_to_date" -eq 1 ]; then
echo "Branch $branch is up to date."
continue
fi
read -p "Push changes to branch $branch? [y/N] " confirm
if [ "$confirm" == "y" ] || [ "$confirm" == "Y" ]; then
# Checkout the branch and push changes
git push --force-with-lease
fi
echo "--------------------"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment