git checkout branch from outside

后端 未结 5 1397
我在风中等你
我在风中等你 2021-01-31 16:18

Problem: I need somehow to checkout an existing branch of a project that is already cloned locally on my file system without being in that particular folder of this project.

5条回答
  •  臣服心动
    2021-01-31 16:22

    git 2.5 added the ability to have multiple working trees using git worktree. So this case, you'd use something like

    git worktree add -b new-branch-name ../dir-name existing-branch

    you can then change to dir-name and make your commits as usual. The commits will end up in your original repository (where you used worktree add).

    When you're done and everything you want is committed, you can delete the dir-name folder and run git worktree prune to clean up the orphaned worktree in your repo.

提交回复
热议问题