Git如何管理遠程倉庫分支?

It’s important to note that when you do a fetch that brings down new remote-tracking branches, you don’t automatically have local, editable copies of them. In other words, in this case, you don’t have a new serverfix branch — you have only an origin/serverfix pointer that you can’t modify

  1. 推送本地分支到遠程(遠程沒有該分支)

    git push <remote> <branch>

    例如將本地serverfix分支推送到遠程,這樣遠程倉庫也有serverfix分支了: git push origin serverfix

  2. 本地拉取遠程分支(本地沒有該分支):兩步走-先拉取再checkout

    $ git fetch origin
    
    $ git checkout -b serverfix origin/serverfix
    

    拉取遠程serverfix分支到本地的serverfix分支

  3. 將本地已有分支與遠程已有分支建立track關係

    如下在本地serverfix分支敲這個命令:將當前分支 與 遠程倉庫的serverfix分支建立track關係

    $ git branch --set-upstream-to origin/serverfix 
    Branch serverfix set up to track remote branch serverfix from origin.
    
    or 簡寫成:
    $ git branch -u origin/serverfix
    
  4. 其他命令

    • 查看本地分支與遠程分支的track關係:git branch -vv

      $ git branch -vv
        iss53     7e424c3 [origin/iss53: ahead 2] Add forgotten brackets
        master    1ae2a45 [origin/master] Deploy index fix
      * serverfix f8674d9 [teamone/server-fix-good: ahead 3, behind 1] This should do it
        testing   5ea463a Try something new
      
    • 遠程倉庫分支列表以及詳細

      列表:git ls-remote <remote>

      詳細:git remote show <remote>

    • 刪除遠程倉庫的分支

      git push origin --delete serverfix

更多討論:
https://github.com/pluscai/use-git/issues/19

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章