Make an existing Git branch track a remote branch?

前端 未结 22 2958
执念已碎
执念已碎 2020-11-21 07:16

I know how to make a new branch that tracks remote branches, but how do I make an existing branch track a remote branch?

I know I can just edit the

22条回答
  •  天涯浪人
    2020-11-21 08:17

    Here, using github and git version 2.1.4, just do:

    $ git clone git@github.com:user/repo.git
    

    And remotes come by itelsef, even if not linked locally:

    $ git remote show origin
    
    * remote origin
      Fetch URL: git@github.com:user/repo.git
      Push  URL: git@github.com:user/repo.git
      HEAD branch: master
      Remote branches:
        develop tracked         <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
        master  tracked
      Local branch configured for 'git pull':
        master merges with remote master
      Local ref configured for 'git push':
        master pushes to master (up to date)
    

    But of course, still no local branch:

    $ git branch
    * master                  <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    

    See? Now if you just checkout develp, it will do the magic automatically:

    $ git checkout develop
    Branch develop set up to track remote branch develop from origin.
    Switched to a new branch 'develop'
    

    So easy!


    Summary. Just run this 2 commands:

    $ git clone git@github.com:user/repo.git
    $ git checkout develop
    

提交回复
热议问题