Skip to content

Instantly share code, notes, and snippets.

@lcpriest
Created May 5, 2020 11:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lcpriest/77ee492790d33f9c5722658d67a564d6 to your computer and use it in GitHub Desktop.
Save lcpriest/77ee492790d33f9c5722658d67a564d6 to your computer and use it in GitHub Desktop.
# git-auto-rebase
# git-auto-rebase --force-push
function git-auto-rebase() {
target="master"
if [[ $@ = "--force-push" ]]
then
push=true
else
push=false
fi
git for-each-ref --format="%(refname:short)" refs/heads | \
while read branch
do
git checkout $branch &> /dev/null
git rebase $target &> /dev/null
if [ "$?" = 0 ]
then
COLOR="\033[0;32m✔"
message="successfully rebased"
if [ "$push" = true ]
then
git push origin $branch --force
fi
else
git rebase --abort
COLOR="\033[0;31m✘"
message="failed to rebase, skipping"
fi
printf "$COLOR %-40s | %s\n" $branch $message
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment