Track a new remote branch created on GitHub

I have already got a local master branch tracking the remote master branch of a github project. Now, a collaborator of mine has created a new branch in the same project, and I want to do the following accordingly:

  • create a new branch locally
  • make this new branch track the newly create remote branch.
  • How should I do it properly?


    git fetch
    git branch --track branch-name origin/branch-name
    

    First command makes sure you have remote branch in local repository. Second command creates local branch which tracks remote branch. It assumes that your remote name is origin and branch name is branch-name .

    --track option is enabled by default for remote branches and you can omit it.


    First of all you have to fetch the remote repository:

    git fetch remoteName
    

    Than you can create the new branch and set it up to track the remote branch you want:

    git checkout -b newLocalBranch remoteName/remoteBranch
    

    You can also use "git branch --track" instead of "git checkout -b" as max specified.

    git branch --track newLocalBranch remoteName/remoteBranch
    

    If you don't have an existing local branch, it is truly as simple as:

    git fetch
    git checkout <remote-branch-name>
    

    For instance if you fetch and there is a new remote tracking branch called origin/feature/Main_Page , just do this:

    git checkout feature/Main_Page
    

    This creates a local branch with the same name as the remote branch, tracking that remote branch. If you have multiple remotes with the same branch name, you can use the less ambiguous:

    git checkout -t <remote>/<remote-branch-name>
    

    If you already made the local branch and don't want to delete it, see How do you make an existing Git branch track a remote branch?.

    链接地址: http://www.djcxy.com/p/4548.html

    上一篇: 改变Git远程'推到'默认值

    下一篇: 跟踪在GitHub上创建的新远程分支