git 本地項目和遠程倉庫關聯

1、本地創建git倉庫,命令:git init

2、本地倉庫和遠程倉庫關聯,假設遠程倉庫在github上,地址爲:https://github.com/xxx/xxx,執行命令:

     git remote add origin https://github.com/xxx/xxx

3、本地項目push到遠程,執行命令:git push origin xxx,具體參考如下情況:

     推送本地分支local_branch到遠程分支 remote_branch並建立關聯關係,分爲如下3種情況:

      (1)遠程已有remote_branch分支且已經關聯本地分支local_branch且本地已經切換到local_branch,執行命令:

          git push

      (2)遠程已有remote_branch分支但未關聯本地分支local_branch且本地已經切換到local_branch,執行命令:

          git push -u origin/remote_branch

      (3)遠程沒有有remote_branch分支並,本地已經切換到local_branch,執行命令:

          git push origin local_branch:remote_branch

 4、若本地push到遠程報錯,需要看是否遠程有更新未pull到本地,執行git命令:

          git pull origin 遠程分支名(如:master)

 5、若在項目新建階段,pull 報錯,可以執行命令:

          git pull origin master --allow-unrelated-history

 

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