Skip to content

Instantly share code, notes, and snippets.

@dhsrocha
Last active March 1, 2023 16:57
Show Gist options
  • Save dhsrocha/0e973550565d7a736f51ff1f6c6e295b to your computer and use it in GitHub Desktop.
Save dhsrocha/0e973550565d7a736f51ff1f6c6e295b to your computer and use it in GitHub Desktop.
Function to rebase all branches from reference one,
#!/bin/sh
# rebase() - Rebase all branches from the specified source branch
#
# Usage:
# rebase <source-branch>
#
# Description:
# This function will check if git is on the PATH, and if the argument "$1"
# has been provided. If not, an error message will be printed and the
# function will exit with an error code. If the argument is present, the
# function will loop through each branch and rebase it with the specified
# source branch. After that, the function will then checkout to the
# provided branch source.
function rebase() {
if [ -z "$(command -v git)" ]; then echo "Error: git is not on the PATH" && exit 1; fi
if [ $# -ne 1 ]; then echo "Error: No branch specified" && exit 1; fi
git for-each-ref --format="%(refname)" refs/heads/ | while read branch; do
git checkout $branch
git rebase $1
done
git checkout $1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment