Skip to content

Instantly share code, notes, and snippets.

Last active Aug 29, 2016
What would you like to do?
Bash script to rebase certain branch onto your current one
# Your project path
cd /path/to/project
# Base branch which will be rebased, suppose it's "master"
# Current branch
curBranch=`git status |head -n 1| grep "branch" | cut -d ' ' -f 4`
# if we're not on baseBranch - update it and do rebase
if [ "$curBranch" != "$baseBranch" ];
echo "Updating $baseBranch"
git co "$baseBranch" && \
git plo "$baseBranch" &&
echo "$baseBranch updated"
echo "Moving to $curBranch and start rebasing"
git co "$curBranch" && \
git rebase "$baseBranch"
# else just update baseBranch
git plo "$baseBranch"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment