Git worktrees with bare repo

Ref: https://medium.com/@fragov/git-worktrees-with-bare-repo-ec24f2c8e518

  1. Git worktrees with bare repo

    mkdir project-dir
    cd project-dir
    
  2. 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 
  1. The next command allows us to use our bare repo from current directory:
echo 'gitdir: $PWD/.bare' > .git
  1. 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/*'
  1. Now we can start to work on different branches:
git worktree add develop
git worktree add new-feature