git: Add branch-rename
Small script to rename a branch locally and on a given remote.
This commit is contained in:
@@ -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"
|
||||
|
||||
26
.config/zsh/autoload/git/git-branch-rename
Executable file
26
.config/zsh/autoload/git/git-branch-rename
Executable file
@@ -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" <<EOF
|
||||
git branch -m "$new" && git push -u && git push -d "$remote" "$old"
|
||||
EOF
|
||||
Reference in New Issue
Block a user