#!/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 example-work cd example-work git init --bare -q --template= --initial-branch=main remote.git git init -q --template= --initial-branch=main project cd project git config commit.gpgsign false git config core.autocrlf false git remote add origin ../remote.git printf 'base\n' > note.txt git add note.txt git commit -qm 'Base note' git push -q -u origin main git switch -q --detach printf 'detached work\n' >> note.txt git add note.txt git commit -qm 'Detached change' saved=$(git rev-parse HEAD) test -z "$(git branch --show-current)" git switch -q -c keep-detached-work test "$(git rev-parse keep-detached-work)" = "$saved" printf 'Detached commit retained by branch keep-detached-work\n' git switch -q main test "$(git log -1 --format='%s' keep-detached-work)" = 'Detached change' printf 'Original branch remains separate\n'