git上傳新項目到coding
1:coding.net註冊賬號,並創建項目.可以將readme.txt打上勾
2:cd到本機的項目文件夾下 在git中代表workspace
3:mac用戶用ls -all ,linux用戶用ll 或者ls -l查看是否已經存在.git文件夾 該文件夾就是repository(本地的git目錄) 如果存在就把它刪掉 rm -rf .git
4:設置git的用戶名和郵箱. 如果是coding的賬號就使用coding的註冊郵箱 和用戶名
改config的用戶名的命令為
git config --global user.name ‘xxx‘
改郵箱的命令為
git config --global user.email ‘[email protected]‘
5:在git中 要將本地項目推送到雲端(例如coding)上必須要先加載到本地的index中 然後推送到git工作站上文中提到的repository
git add . #表示添加所有文件 git add index.html #index.html表示某一個文件名
6:添加後可以使用status查看git的狀態
chenjiadeMBP:Questionnaire chenjia$ git status
On branch master
nothing to commit, working tree clean
出現這種表示沒有上傳到
7:add之後 用commit命令 推送到git工作站也就是上文中提到的repository
git commit -m ‘說明‘ #說明中一般填寫提交人的姓名和修改的內容 例如我測試一下而已就寫個test
8:最關鍵的一步 到這裏千萬不能直接網上push 一定要先將coding上的版本pull下來 來達到版本一致,否則會報錯
To https://git.coding.net/cjkk/QuestionNaire.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to ‘https://git.coding.net/cjkk/QuestionNaire.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.
git pull https://git.coding.net/cjkk/QuestionNaire.git --allow-unrelated-histories #那個https的地址是自己的coding目錄的網址
9:最後一步了
git push --set-upstream https://git.coding.net/cjkk/QuestionNaire.git master #同上換下地址
最後更改分支問題了
和把大象放到冰箱裏一樣 需要三步
1.打開冰箱
git checkout -b dev #創建並切換到dev分支 可以自己改分支名
介紹一下git branch 查看分支狀態 git branch + 名字 創建分支名 git checkout +分支名 切換到指定分支
chenjiadeMBP:Questionnaire chenjia$ git branch
* master
chenjiadeMBP:Questionnaire chenjia$ git branch ccc
chenjiadeMBP:Questionnaire chenjia$ git branch
ccc
* master
chenjiadeMBP:Questionnaire chenjia$ git checkout ccc
Switched to branch ‘ccc‘
chenjiadeMBP:Questionnaire chenjia$ git branch
* ccc
master
2: 把大象放進去 當前已經是在分支下了,可以進行正常的增刪改查操作,都不會影響主分支 類似linux虛擬機的快照功能和古老的系統備份功能
vim test.txt #創建一個test.txt 自己隨便寫點東西在裏面 git add test.txt git commit -m ‘測試分支功能‘
這樣就是在分支中完成了
3:關門 不關門浪費電 當在dev分支下把階段任務完成時,直接切回master分支,並把master分支指向dev 之後dev就可以刪掉了
git checkout master #切換到master分支 git merge dev #merge合並的意思 將master和dev合並,原理就是將master走到dev那 git branch -d dev #刪除分支命令
over
git上傳新項目到coding