Last active
March 1, 2023 16:57
-
-
Save dhsrocha/0e973550565d7a736f51ff1f6c6e295b to your computer and use it in GitHub Desktop.
Function to rebase all branches from reference one,
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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