Last active
March 2, 2026 17:42
-
-
Save liuliu/962d0fbe82b1f8aa18dcfc73687c835d to your computer and use it in GitHub Desktop.
./relocate_to_git_worktree.sh {Your current git repo}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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