Skip to content

Instantly share code, notes, and snippets.

@sheepmaster
Last active February 16, 2024 11:44
Show Gist options
  • Select an option

  • Save sheepmaster/1484771 to your computer and use it in GitHub Desktop.

Select an option

Save sheepmaster/1484771 to your computer and use it in GitHub Desktop.
#!/bin/sh
USAGE='[-b <branch>] [--interactive | -i] [-v] [--quiet | -q] <base> [<target>]'
SUBDIRECTORY_OK=Yes
. git-sh-setup
rebase_options=
set -e
while test $# != 0
do
case "$1" in
-b)
test 2 -le "$#" || usage
branch="$2"
shift
;;
-i|--interactive|-v|-q|--quiet)
rebase_options="$rebase_options $1"
;;
-*)
usage
;;
*)
break
;;
esac
shift
done
test $# -lt 1 && usage
test $# -gt 2 && usage
base=$1
target=$2
if test -z "$target"
then
target="$base"
fi
head=$(git symbolic-ref HEAD) || die "Must be on a branch."
# Save $target in case we change it below
old_target=$(git rev-parse "$target")
if test -n "$branch"
then
git checkout -q -b "$branch"
else
git checkout -q -B "$target"
fi
git update-ref -m "Transplanting '$head'" "$head" "$base"
if test "$target" != "$base"
then
git rebase $rebase_options --onto "$old_target" "$base"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment