gitgit-worktree

How do I pull a branch from origin to local while working with git-worktree?


What I am used to in the main worktree land:

on branch main, I run git pull origin/main, this fast forwards and pulls all refs down to my local. My co-worker's branch is newFeature, so I run git checkout newFeature and I am on that branch!

How do I do the same when working with a bare repo and git worktrees? I cannot figure out how to checkout newFeature locally, such that I have a folder right beside my main


Solution

  • If you need multiple working directories with Git, you can:

    That will create a newFeature for that branch, beside your local repo folder.


    The OP Saiborg confirms in the comments:

    In order for me to do what I wanted, I just had to do this:

    git worktree add -b feature/newFeature newFeature origin/feature/newFeature 
    

    which worked as expected.