Skip to content

Instantly share code, notes, and snippets.

@wgirhad
Last active December 17, 2021 13:07
Show Gist options
  • Save wgirhad/e9f5e52ca11a15b0ba32bd5d734320e4 to your computer and use it in GitHub Desktop.
Save wgirhad/e9f5e52ca11a15b0ba32bd5d734320e4 to your computer and use it in GitHub Desktop.
Script to merge/push your current branch to n different branches
#!/bin/bash
# Usage examples:
# merge-to master staging development
# merge-to master, staging, development
# merge-to origin/master, origin/staging, origin/development
current=`git rev-parse --abbrev-ref HEAD`
remotes=`git remote`
git fetch --all
for arg in $@
do
branch=$arg
for remote in $remotes
do
branch=`echo $branch | sed -e "s|^$remote/||" -re 's/,+$//'`
done
git checkout $branch
git reset --hard `git rev-parse --abbrev-ref --symbolic-full-name @{u}`
git merge --no-edit $current
git push
done
git checkout $current
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment