Git worktrees with bare repo
January 25, 2022•183 words
Ref: https://medium.com/@fragov/git-worktrees-with-bare-repo-ec24f2c8e518
Git worktrees with bare repo
mkdir project-dir cd project-dir
Clone your repo with
bare
parameter, to the .bare directory (As we want to avoid seeing all bare repo stuff, it is better to clone it to a separate directory, and then just “tell” git, where to get your repo information):
git clone --bare git@your-server:yourrepo.git .bare
- The next command allows us to use our bare repo from current directory:
echo 'gitdir: $PWD/.bare' > .git
- Now we have to update our git config for our repo, as when a “bare” git clone is performed, it doesn’t set which refs should be updated when performing a git fetch. This is mostly because it’s assumed that a bare checkout won’t have a working tree, which isn’t true in our case, where we have workrees alongside a bare checkout. If you just run the following, it should resolve this issue:
git config remote.origin.fetch '+refs/heads/*:refs/remotes/origin/*'
- Now we can start to work on different branches:
git worktree add develop
git worktree add new-feature