Checkout branch on different remote

前端 未结 3 843
难免孤独
难免孤独 2021-02-06 23:22

I have a repo that has another remote upstream besides origin. I can do git checkout origin/master, but when I run git checkout upst

相关标签:
3条回答
  • 2021-02-06 23:57

    Just fetch the refs from the remote (this will fetch all branch, commit, refs etc for the upstream repo)

    git fetch upstream
    

    After this, checkout the needed branch (this creates a local copy of the branch)

    git checkout -b <branchname> --track upstream/<branchname>
    

    Now if you want to pull the changes in this branch in future, all you need to do is

    git pull upstream <branchname>
    

    As mentioned here, try doing an explicit fetch on the branch name:

    git fetch upstream master:branch_name
    
    0 讨论(0)
  • 2021-02-07 00:13

    In more concise way (I'm using git 2.28), you can say

    git fetch upstream
    

    and then

    git checkout -b <branch_name> --guess
    

    where the --guess flag checks if a branch corresponding to <branch_name> exists on any of the remotes and tracks the corresponding remote (docs here).

    0 讨论(0)
  • 2021-02-07 00:16

    If you just added the remote, you'll need to fetch it so that Git knows which branches are available:

    git fetch upstream master
    

    After this you can do

    git checkout upstream/master
    

    without any issues.

    0 讨论(0)
提交回复
热议问题