Skip to content

Instantly share code, notes, and snippets.

@u-mulder u-mulder/git_rb.sh
Last active Aug 29, 2016

Embed
What would you like to do?
Bash script to rebase certain branch onto your current one
#!/bin/bash
# Your project path
cd /path/to/project
# Base branch which will be rebased, suppose it's "master"
baseBranch="base_branch"
# 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" ];
then
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
# else just update baseBranch
git plo "$baseBranch"
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.