Skip to content

Commit 4a05ad2

Browse files
committed
git-rename-branch: use detected upstream remote
1 parent b00aace commit 4a05ad2

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

bin/git-rename-branch

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
#!/usr/bin/env bash
2+
set -e
23

34
# Assert there is at least one branch provided
45
test -z $1 && echo "new branch name required." 1>&2 && exit 1
56

67
new_branch="$1"
78
old_branch="${2-$(git symbolic-ref --short -q HEAD)}"
9+
remote=$(git config branch."$old_branch".remote)
810

911
git branch -m "$old_branch" "$new_branch"
10-
git push origin :"$old_branch"
11-
git push --set-upstream origin "$new_branch"
12+
# check if the branch is tracking a remote branch
13+
if [[ -n "$remote" && "$remote" != "." ]]
14+
then
15+
git push "$remote" :"$old_branch"
16+
git push --set-upstream "$remote" "$new_branch"
17+
fi

0 commit comments

Comments
 (0)