Skip to content

Instantly share code, notes, and snippets.

@slucero
Created December 8, 2015 19:11
Show Gist options
  • Save slucero/258dda2ac764cd5550f8 to your computer and use it in GitHub Desktop.
Save slucero/258dda2ac764cd5550f8 to your computer and use it in GitHub Desktop.
Git command script to merge a single branch into multiple others.
#!/bin/bash
##############################
# Merge the current branch into multiple other local branches.
#
# TODO: Add the option to pass additional arguments to merge commands
##############################
# Determine the current branch name
source=$(git symbolic-ref HEAD 2> /dev/null) || source=$(git rev-parse --short HEAD 2> /dev/null);
# Strip prefix from branch name
source=${source#refs/heads/};
targets=$*;
for target in $*
do
git checkout $target;
if ! git merge --no-ff $source; then
printf 'Failed to merge "%s" into "%s"\n' $source $target >&2
exit 1
fi
git checkout $source;
done
exit 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment