Skip to content

Commit 49771ba

Browse files
authored
Merge pull request #636 from spacewander/fix_rename_branch
use remote detected instead of 'origin' in rename-branch
2 parents 6e9da2a + 4a05ad2 commit 49771ba

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)