Created
February 5, 2026 04:33
-
-
Save usami/30167fa20e9d1c47dbd791f7524390d7 to your computer and use it in GitHub Desktop.
git worktree with bare clone
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
| # 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