How do I check out a remote Git branch?

后端 未结 30 2487
灰色年华
灰色年华 2020-11-22 00:12

Somebody pushed a branch called test with git push origin test to a shared repository. I can see the branch with git branch -r.

<
30条回答
  •  轮回少年
    2020-11-22 00:20

    You can start tracking all remote branches with the following Bash script:

    #!/bin/bash
    git fetch --all
    for branch in `git branch -r --format="%(refname:short)" | sed 's/origin\///'`
      do git branch -f --track "$branch" "origin/$branch"
    done
    

    Here is also a single-line version:

    git fetch --all; for branch in `git branch -r --format="%(refname:short)" | sed 's/origin\///'`; do git branch --track "$branch" "origin/$branch" ; done ;
    

提交回复
热议问题