-
ssh-keygen
在本地電腦中中生成鑰匙 - 打開公鑰
id-rsa.pub
耕捞,將公鑰copy到git網(wǎng)站的SSH KEYS
中梨睁。
-
git clone
將服務(wù)器中的代碼git到本地郭宝,copy項(xiàng)目網(wǎng)頁上的ssh連接 - 提交代碼
- 先創(chuàng)建一個branch 涡贱,進(jìn)入項(xiàng)目目錄钓葫,輸入命令行
git branch username
這個樣就創(chuàng)建了一個本地的branch.
輸入git checkout username
轉(zhuǎn)到當(dāng)前branch
git branch
查看本地多少branch. 查看遠(yuǎn)程分支
git branch -r
- 在目錄中添加新文件后,可以
git status
看一下文件改變狀態(tài) - 之后
git add
確定添加 參數(shù)-u
代表更新的代碼嵌灰, 參數(shù)-A
表示所有弄匕,add到本地倉庫 - 之后
git commit -m "作用"
將,參數(shù)-m
表示本次提交描述沽瞭,表示確認(rèn)提交到本地倉庫 -
git push -u orgin youbranch
提交到遠(yuǎn)程
注:
- $ git push -u origin master //第一次提交添加命令參數(shù) -u 確保關(guān)聯(lián)本地庫和遠(yuǎn)程庫
- $ git push origin master //非第一次提交使用此命令即可)
如果出現(xiàn)報錯
$ git push -u origin master命令的時候報錯:To git@github.com:xxx/xxx.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'git@github.com:xxx/xxx.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
原因是沒有同步遠(yuǎn)程的master迁匠,所以需要先執(zhí)行命令git pull origin master
同步代碼
之后就可以同步了。
-
git pull -r
將項(xiàng)目代碼拉到本地驹溃。