How to fork a new branch from a repo when you already have the master?

前端 未结 1 524
滥情空心
滥情空心 2021-01-06 21:17

I have forked a repo into my own github account and have successfully pulled it to my PC, however there is now a new branch on the original repo that I want as well but when

相关标签:
1条回答
  • 2021-01-06 21:58

    Once you have cloned your fork, you can on your local cloned repo add a new remote referencing the original repo (the one you have forked, and the one where a new branch of interest just appeared)

    It is the triangular workflow:

    What you do is:

    cd /path/to/local/repo
    git remote add upstream /url/of/original/repo
    git fetch upstream
    

    That last fetch will include the new branch (in the remotes/upstream namespace)

    From there, you can easily create a local branch starting from that upstream/newBranch and push it to your fork (referenced by the remote named 'origin')

    git checkout -b newBranch upstream/newBranch
    git push -u origin newBranch
    
    0 讨论(0)
提交回复
热议问题