(此處我以碼云為例)
常用命令:
-
新增遠端倉庫:git remote add origin 倉庫地址
(origin只是一個名字,對遠端倉庫的一個名字,習慣上用origin)
-
從倉庫拉取內容:git pull origin master --allow-unrelated-histories
-
git push -u origin master
步驟:
1. 建立遠端倉庫:

2. 進入要推送到遠端倉庫的目錄下(建立git版本庫,不懂可參考上面的 “ 建立並提交內容到git版本庫 ”)
3. 若不知該目錄下是否已建立了git倉庫,可輸入檢視命令:ls -a
(-a是指把隱藏檔案也顯示出來,因為 .git檔案是隱藏檔案)
有.git檔案代表已建立了git倉庫,否則要建立:git init

4. 接著就是把工作區的內容提交到git倉庫:
(因為一般都建議有README.md檔案,所以這裡我也建立了一個)

5. 把本地git倉庫與遠端倉庫關聯起來:git remote add origin 遠端倉庫地址
(origin只是一個名字,對遠端倉庫的一個名字,習慣上用origin。若你要關聯多個遠端倉庫,就要取不同的名字了)
(遠端倉庫地址如下圖處獲取。若有配置SSH連線,就選擇SSH,否則就選HTTPS)

- 關聯後,push到遠端倉庫即可:git push -u origin master
(origin這個名字,要和上面git romote命令的名字保持一致,)
(-u 是把本地的master和遠端倉庫的master分支繫結了(若有其他分支也可繫結其他分支),下次再push就不需要寫分支名了)

碼雲倉庫上重新整理一下就會看到push的檔案了

6. 至此第一次push已完成啦!!
7. 那麼,修改後如何再次puh呢?
8. 修改後的push 其實就是少了初始化版本庫以及與遠端倉庫連通這兩個步驟而已:

push到遠端倉庫:git push
(注意,第一次push的時候是git push -u origin master,而這次不需要寫-u後面了,因為第一次的時候已經把本地和遠端的master分支關聯起來了)
