Skip to content

Instantly share code, notes, and snippets.

@u-mulder
Last active August 29, 2016 09:52
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save u-mulder/0c0353ae5f125210c1337c2a922befb6 to your computer and use it in GitHub Desktop.
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