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

Time:01-21

What I am used to in the main worktree land:

  • I want to work on my co-workers branch as they are on holiday

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

CodePudding user response:

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

  • clone your bare repository

  • from within that cloned repo folder, type:

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

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.

  • Related