support rebasing existing branch
This commit is contained in:
@@ -1,10 +1,27 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
if [ $# -eq 1 ]; then
|
set -eu
|
||||||
branch=$1
|
|
||||||
git fetch upstream master
|
if [ $# -ne 1 ]; then
|
||||||
git checkout upstream/master
|
echo "Usage: $(basename "$0") <branch>" >&2
|
||||||
git checkout -b "$branch"
|
exit 2
|
||||||
else
|
|
||||||
echo "Please specify new branch."
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
branch="$1"
|
||||||
|
base_remote="upstream"
|
||||||
|
base_branch="master"
|
||||||
|
base_ref="$base_remote/$base_branch"
|
||||||
|
|
||||||
|
# avoid rebasing with a dirty tree
|
||||||
|
if ! git diff --quiet || ! git diff --cached --quiet; then
|
||||||
|
echo "Working tree has uncommitted changes; commit/stash first." >&2
|
||||||
|
exit 2
|
||||||
|
fi
|
||||||
|
|
||||||
|
git fetch "$base_remote" "$base_branch"
|
||||||
|
|
||||||
|
if git show-ref --verify --quiet "refs/heads/$branch"; then
|
||||||
|
git checkout "$branch"
|
||||||
|
git rebase "$base_ref"
|
||||||
|
else
|
||||||
|
git checkout -b "$branch" "$base_ref"
|
||||||
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user