git checkout branch from outside

后端 未结 5 1371
我在风中等你
我在风中等你 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:25

    You're quite welcome to use --git-dir and --work-tree to avoid cd'ing, but honestly, it's easier just to cd. To avoid having to cd back, you can do it in a subshell:

    git clone foo foo-copy
    (cd foo-copy && git checkout branch)
    

    Of course, in this specific case, you don't actually need two commands:

    git clone -b  foo foo-copy 
    

提交回复
热议问题