Skip to content

Instantly share code, notes, and snippets.

@clairesrc
Last active September 9, 2019 14:54
Show Gist options
  • Save clairesrc/3117870988338bdf071a40e556858b25 to your computer and use it in GitHub Desktop.
Save clairesrc/3117870988338bdf071a40e556858b25 to your computer and use it in GitHub Desktop.
Trunk Rebase Utility
#!/bin/bash
BASEBRANCH=${1:-master}
HEADBRANCH=`git rev-parse --abbrev-ref HEAD`
if [ "$BASEBRANCH" == "--help" ] || [ "$BASEBRANCH" == "-h" ];
then
echo "Usage: rebase BASEBRANCH (defaults to master)"
echo "Re-run the same command after fixing conflicts to reset upstream branch and push."
exit
fi
echo Rebasing $HEADBRANCH from $BASEBRANCH
git fetch --all
git branch --set-upstream-to origin/$BASEBRANCH
git pull --rebase && git branch --set-upstream-to origin/$HEADBRANCH && git push origin HEAD -f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment