Skip to content

Instantly share code, notes, and snippets.

@yeuser
Last active September 10, 2020 13:59
Show Gist options
  • Save yeuser/071c92ef9d67664110c5962c4421f67a to your computer and use it in GitHub Desktop.
Save yeuser/071c92ef9d67664110c5962c4421f67a to your computer and use it in GitHub Desktop.
This sh file helps you when you work in a strict rebase-then-merge git policy environment. This would essentially keep the chronology of your commits even after they are rebased.
#!/bin/sh
set -e
changes=`git status -s | grep -v "??" | wc -l`
if [ "$changes" -gt "0" ]; then
echo "found $changes local changes. stashing them."
git stash
fi
current_branch=`git branch | grep '*' | cut -d ' ' -f2`
echo "update develop from origin"
git pull origin develop:develop
echo "Rebasing branches: "
for branch in `git branch | grep -v master | grep -v develop | sed -e s/\*//g`; do
echo " branch: $branch"
git checkout $branch
echo " rebasing over develop ... "
git rebase --committer-date-is-author-date develop
git push -f
done
echo "All branches are rebased. going back to develop"
git checkout "$current_branch"
if [ "$changes" -gt "0" ]; then
echo "bringing back local changes"
git stash pop
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment