Skip to content

Instantly share code, notes, and snippets.

@frogonwheels
Created June 29, 2012 01:46
Show Gist options
  • Save frogonwheels/3015185 to your computer and use it in GitHub Desktop.
Save frogonwheels/3015185 to your computer and use it in GitHub Desktop.
An idea for incorporating a topic branch
#!/bin/bash
gitdir=$(git rev-parse --git-dir)
if [ -z ${gitdir} ] ; then
exit 1
fi
if [ "$1" == "" ] ; then
echo Syntax: incorporate branchname
exit 1
fi
target_branch=$(git rev-parse --symbolic-full-name $1)
if [ "${target_branch:0:11}" != "refs/heads/" ] ; then
echo $1 is not a branch 1>&2
exit 1
fi
target_branch_base=${target_branch:11}
current_branch=$(git rev-parse --symbolic-full-name HEAD)
if [ "${current_branch:0:11}" != "refs/heads/" ] ; then
echo Not on a branch 1>&2
exit 1
fi
current_branch_base=${current_branch:11}
common_base=$(git merge-base HEAD $1)
if [ -z "${common_base}" ] ; then
echo No common base 1>&2
exit 1
fi
if git rebase --onto ${current_branch_base} ${common_base} ${target_branch} ; then
git update-ref ${current_branch} HEAD -m "Incorporate $1 into branch"
git checkout ${current_branch_base}
else
echo Failed ${target_branch} ${current_branch}
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment