diff --git a/.config/git/config b/.config/git/config index ced8423..73c8a5f 100644 --- a/.config/git/config +++ b/.config/git/config @@ -12,6 +12,7 @@ abort = "!git-zsh-autoload abort" autosquash = -c sequence.editor=/bin/true rebase -i --autosquash autofixup= autosquash + branch-rename = "!git-zsh-autoload branch-rename" c = commit changes = flog HEAD...FETCH_HEAD checkout-worktree = "!git-zsh-autoload checkout-worktree" diff --git a/.config/zsh/autoload/git/git-branch-rename b/.config/zsh/autoload/git/git-branch-rename new file mode 100755 index 0000000..2556984 --- /dev/null +++ b/.config/zsh/autoload/git/git-branch-rename @@ -0,0 +1,26 @@ +#!/usr/bin/env zsh +# SPDX-License-Identifier: MIT +# Copyright (c) 2025 Julian Prein +# +# Rename a branch locally and on a given remote. + +emulate -L zsh -o err_return -o no_unset + +if (( # < 2 || # > 3 )); then + printf >&2 "Usage: %s OLD NEW [REMOTE]\n" "${0:t}" + return 1 +fi + +local old new remote +old="$1" +new="$2" +remote="${3:-origin}" + +if ! git remote -v | awk '{ print $1 }' | uniq | grep -q "$remote"; then + printf >&2 "Remote '%s' does not exist\n" "$remote" + return 1 +fi + +git checkout-worktree "$old" <