Skip to content

Instantly share code, notes, and snippets.

@liuliu
Last active March 2, 2026 17:42
Show Gist options
  • Select an option

  • Save liuliu/962d0fbe82b1f8aa18dcfc73687c835d to your computer and use it in GitHub Desktop.

Select an option

Save liuliu/962d0fbe82b1f8aa18dcfc73687c835d to your computer and use it in GitHub Desktop.
./relocate_to_git_worktree.sh {Your current git repo}
#!/usr/bin/env bash
set -euo pipefail
mkdir -p _git
BRANCH=$(git --git-dir=$1/.git branch --show-current)
mv $1/.git _git/$1.git
git --git-dir=_git/$1.git config core.bare true
mv $1 $1_tmp
git --git-dir=_git/$1.git worktree add $1 -b $1_tmp
git --git-dir=$1/.git checkout $BRANCH
git --git-dir=$1/.git branch -d $1_tmp
mv $1/.git $1_tmp/.git
rm -rf $1
mv $1_tmp $1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment