Skip to content

Instantly share code, notes, and snippets.

@amlinger
Created February 28, 2016 13:41
Show Gist options
  • Save amlinger/726a87e3b1031135ada5 to your computer and use it in GitHub Desktop.
Save amlinger/726a87e3b1031135ada5 to your computer and use it in GitHub Desktop.
Rebase from base branch
#!/bin/bash
# Fetch the base branch to rebase to. Defaults to master.
BASE_BRANCH=${1-master}
# Fetch the number of commits
COMMITS=$(git log "$BASE_BRANCH".."$(git rev-parse --abbrev-ref HEAD)" --pretty=oneline | wc -l | awk '{print $1}')
# Rebase to original, base branch
git rebase $BASE_BRANCH
# Interactive rebase from the number of commits diverged from original branch
git rebase -i head~"$COMMITS"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment