Skip to content

Instantly share code, notes, and snippets.

@usami
Created February 5, 2026 04:33
Show Gist options
  • Select an option

  • Save usami/30167fa20e9d1c47dbd791f7524390d7 to your computer and use it in GitHub Desktop.

Select an option

Save usami/30167fa20e9d1c47dbd791f7524390d7 to your computer and use it in GitHub Desktop.
git worktree with bare clone
# create a project dir
mkdir my-project && cd my-project
# bare clone into .bare
git clone --bare git@github.com:user/repo.git .bare
# create .git to refer bare repository
echo "gitdir: ./.bare" > .git
# configure and fetch origin
git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
git fetch origin
# add worktrees
git worktree add main main
git worktree add feature/a -b feature/a origin/main
# use existing remote branch
git worktree add feature/b origin/feature/b
# project directory structure
my-project/
├── .bare/ # Git data
├── .git # gitdir ref
├── main/ # main branch worktree
│ ├── src/
│ └── ...
└── feature/
├── a/ # feature/a branch
└── b/ # featrue/b branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment