git checkout branch from outside

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

    Since Git version 1.8.5, you can also use -C option. Be sure to use it before any other command:

    git -C ~/my-git-repo checkout master

    Note that it doesn't have to be specifically the .git folder. Here is the man documenation:

    -C 
           Run as if git was started in  instead of the current 
           working directory. When multiple -C options are given, each
           subsequent non-absolute -C  is interpreted relative to
           the preceding -C .
    
           This option affects options that expect path name like --git-dir
           and --work-tree in that their interpretations of the path names
           would be made relative to the working directory caused by the -C option.
           For example the following invocations are equivalent:
    
               git --git-dir=a.git --work-tree=b -C c status
               git --git-dir=c/a.git --work-tree=c/b status
    

提交回复
热议问题