File: git-rename-branch

package info (click to toggle)
git-extras 7.4.0-1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 2,120 kB
  • sloc: sh: 4,312; python: 994; makefile: 146
file content (23 lines) | stat: -rwxr-xr-x 571 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/usr/bin/env bash
set -e

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

if [ -z "$2" ]; then
    new_branch="$1"
    old_branch="$(git symbolic-ref --short -q HEAD)"
else
    new_branch="$2"
    old_branch="$1"
fi

remote=$(git config branch."$old_branch".remote; true)

git branch -m "$old_branch" "$new_branch"
# check if the branch is tracking a remote branch
if [[ -n "$remote" && "$remote" != "." ]]
then
    git push "$remote" :"$old_branch"
    git push --set-upstream "$remote" "$new_branch"
fi