Git - separate folder for each branch. Setting it up

前端 未结 4 1824
鱼传尺愫
鱼传尺愫 2021-02-01 10:08

I have a need to keep 3 branches in 3 separate folders. (I know this is not a git way of doing things. But I need to do this for a reason).

Lets say the repo name is

4条回答
  •  南旧
    南旧 (楼主)
    2021-02-01 10:18

    What you want to achieve has become simpler (or even trivial) since git 2.5 introduced the git worktree command.

    Basically, your your git repo has now completely free number of checked out branches, called work tree:

    • 0 (a bare repo)
    • 1 (a normal repo)
    • n > 1, a normal repo where you added n-1 work trees

    If your repo already contains your branch, you can do:

    git worktree add  
    

    Or, if that branch isn't created yet and you want to branch off master:

    git worktree add -b   master
    

    Note that you can't checkout a branch in several directories simultaneously.

提交回复
热议问题