Merge, update, and pull Git branches without using checkouts

前端 未结 17 1712
臣服心动
臣服心动 2020-11-22 07:42

I work on a project that has 2 branches, A and B. I typically work on branch A, and merge stuff from branch B. For the merging, I would typically do:

git mer         


        
17条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-22 08:33

    git worktree add [-f] [--detach] [--checkout] [--lock] [-b ]  []
    

    You can try git worktree to have two branches open side by side, this sounds like it might be what you want but very different than some of the other answers I've seen here.

    In this way you can have two separate branches tracking in the same git repo so you only have to fetch once to get updates in both work trees (rather than having to git clone twice and git pull on each)

    Worktree will create a new working directory for your code where you can have a different branch checked out simultaneously instead of swapping branches in place.

    When you want to remove it you can clean up with

    git worktree remove [-f] 
    

提交回复
热议问题