#!/bin/sh # SPDX-License-Identifier: MIT set -eu export TZ=UTC LC_ALL=C export GIT_CONFIG_NOSYSTEM=1 GIT_CONFIG_GLOBAL=/dev/null export GIT_AUTHOR_NAME='Example Author' GIT_AUTHOR_EMAIL='author@example.invalid' export GIT_COMMITTER_NAME='Example Author' GIT_COMMITTER_EMAIL='author@example.invalid' export GIT_AUTHOR_DATE='2026-10-27T12:00:00+00:00' export GIT_COMMITTER_DATE='2026-10-27T12:00:00+00:00' test "$(git version)" = 'git version 2.56.0' mkdir rename-example cd rename-example git init --template= --bare -q --initial-branch=main origin.git git init --template= -q --initial-branch=main repo cd repo printf 'base\n' > note.txt git add note.txt git commit -qm 'Base' git remote add origin ../origin.git git push -q -u origin main >/dev/null git switch -qc old-name printf 'topic\n' >> note.txt git commit -qam 'Topic work' git push -q -u origin old-name >/dev/null before=$(git rev-parse HEAD) git branch -m new-name test "$(git rev-parse HEAD)" = "$before" test "$(git branch --show-current)" = new-name test "$(git rev-parse --abbrev-ref --symbolic-full-name '@{upstream}')" = origin/old-name printf 'Local name changed; upstream still names origin/old-name\n' git push -q -u origin new-name >/dev/null git push -q origin --delete old-name test "$(git rev-parse --abbrev-ref --symbolic-full-name '@{upstream}')" = origin/new-name git --git-dir=../origin.git show-ref --verify --quiet refs/heads/new-name test "$(git --git-dir=../origin.git rev-parse refs/heads/new-name)" = "$before" if git --git-dir=../origin.git show-ref --verify --quiet refs/heads/old-name; then exit 1; fi printf 'Remote has new-name; old-name was deleted; upstream updated\n'