Skip to content

Instantly share code, notes, and snippets.

@DanCech
Created September 13, 2022 14:19
Show Gist options
  • Save DanCech/52e2dc86d4ebbda486f85f071b81a6bc to your computer and use it in GitHub Desktop.
Save DanCech/52e2dc86d4ebbda486f85f071b81a6bc to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# set -x
PRIMARY_BRANCH='master'
if [ -n "$(git branch -l main)" ]; then
PRIMARY_BRANCH=main
fi
BRANCH=$(git symbolic-ref --short HEAD)
BASEBRANCH=${1:-$PRIMARY_BRANCH}
OLDBASE=`diff -u <(git rev-list --first-parent $BRANCH) <(git rev-list --first-parent $BASEBRANCH) | sed -ne 's/^ //p' | head -1`
git rebase --onto $BASEBRANCH $OLDBASE $BRANCH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment