Git手册 - 分支远程同步
一)將本地分支連接到遠程分支,這里以GitHub上的同名倉庫(項目)為例
1)進入本地項目主分支
2)運行以下命令:
#git remote add origin git@github.com:path/repoName.git????????//將遠程倉庫命名為origin
3)當本地倉庫與遠程倉庫都僅有一個主分支時,運行以下命令:
#git push -u origin master????????//加參數-u,git不僅會將本地主分支所有內容推送到遠程主分支,還會自動將本地主分支與遠程主分支連接起來
注:
1)手動建立分支連接命令:
#git branch --set-upstream-to=origin/branchName branchName(local)
2)如果本地倉庫有多個分支,則需先手動建立對應分支連接,然后pull,最后再push來實現同步:
#git checkout branchName????????//默認master分支
#git branch --set-upstream-to=origin/branchName branchName(local)
#git pull origin branchName --allow-unrelated-histories
#git push
***Master以外其他分支:
#git checkout branchName??
#git push --set-upstream origin branchName????//將分支推送至遠程端,從而在遠程端創建同名的分支
二)克隆遠程倉庫
1)通過SSH
git clone ?git@github.com:TaoismLEE/Git.git
Notes 1:
????A. After modifying, use: "git push origin master" to push the modification.
????B. Can use: git remote -v to check the information about remote repository.
Notice 2:
If clone using SSH method, the data transfered between Git and Github will be encrypted with SSH key, so some settings should be made firstly in order to fetch the project from Github successfully:
Setting SSH key:
????A. In home folder, check whether the .ssh folder exists, if exists,then check whether there are "id_rsa" and "id_rsa.pub" files
????B. If the folder or the files not exist, then generate them by running following commands:
????#ssh-keygen -t rsa -C "email-address" //configured email of git
????C. Setting SSH Key in Github with the content of id_rsa.pub file //Open "Account settings" -> "SSH Keys"; then click "Add SSH Key";fill in "Title"; in the Key textarea, paste the content of id_rsa.pub file
2)通過HTTPS
git clone https://github.com/TaoismLEE/Git.git
or
git clone https://LoginUserName@github.com/TaoismLEE/Git.git
Notice:
If clone using HTTPS method, will need accout and password of remote Github when pushing modification to remote repository. OR running below command to store and remember the remote account information:
#git config --global credential.helper store
3)克隆后獲取非主分支
#git checkout -b dev(suggest to name the new local branch the same with the remote branch) origin/dev(other branch in remote repository)
三)協同工作
A. First, try to use "git push origin branch-name" to push our own modification
B. If conflict, then should use "git pull" to pull out the latest code
C. Fix conflicts manually and commit as a new version
D. Run "git push origin branch-name" again to push our code?
轉載于:https://blog.51cto.com/taoismli/1936951
總結
以上是生活随笔為你收集整理的Git手册 - 分支远程同步的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 树莓派进阶之路 (014) - 树莓派远
- 下一篇: 《算法设计手册》面试题解答 第四章:排序