Last active
April 13, 2023 07:48
-
-
Save lzap/1ef1709b373ca073ca79538bc76500d2 to your computer and use it in GitHub Desktop.
Script to fetch all branches and fast forward merge master/main/develop without checkout
This file contains 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/bash | |
#UPSTREAM=origin | |
UPSTREAM=upstream | |
function bexists() { | |
local branch=${1} | |
local existed_in_local=$(git branch --list ${branch}) | |
if [[ -z ${existed_in_local} ]]; then | |
echo 0 | |
else | |
echo 1 | |
fi | |
} | |
git fetch --all | |
for BRANCH in main master develop; do | |
echo "Trying $BRANCH" | |
if [[ $(bexists $BRANCH) -eq 1 ]]; then | |
if [[ $(git rev-parse --abbrev-ref HEAD) == "$BRANCH" ]]; then | |
echo "Merging $UPSTREAM/$BRANCH into the current branch" | |
git merge --ff-only $UPSTREAM/$BRANCH | |
else | |
echo "Merging $UPSTREAM/$BRANCH into $BRANCH" | |
git fetch $UPSTREAM $BRANCH:$BRANCH | |
fi | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment