-
ssh-keygen在本地電腦中中生成鑰匙 - 打開(kāi)公鑰
id-rsa.pub,將公鑰copy到git網(wǎng)站的SSH KEYS中。
-
git clone將服務(wù)器中的代碼git到本地,copy項(xiàng)目網(wǎng)頁(yè)上的ssh連接 - 提交代碼
- 先創(chuàng)建一個(gè)branch ,進(jìn)入項(xiàng)目目錄,輸入命令行
git branch username這個(gè)樣就創(chuàng)建了一個(gè)本地的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到本地倉(cāng)庫(kù) - 之后
git commit -m "作用"將,參數(shù)-m表示本次提交描述,表示確認(rèn)提交到本地倉(cāng)庫(kù) -
git push -u orgin youbranch提交到遠(yuǎn)程
注:
- $ git push -u origin master //第一次提交添加命令參數(shù) -u 確保關(guān)聯(lián)本地庫(kù)和遠(yuǎn)程庫(kù)
- $ git push origin master //非第一次提交使用此命令即可)
如果出現(xiàn)報(bào)錯(cuò)
$ git push -u origin master命令的時(shí)候報(bào)錯(cuò):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.
原因是沒(méi)有同步遠(yuǎn)程的master,所以需要先執(zhí)行命令git pull origin master同步代碼
之后就可以同步了。
-
git pull -r將項(xiàng)目代碼拉到本地。