注意:我是在coding.net上建立的一個(gè)新的項(xiàng)目爆袍,沒有初始化岂傲,
啟用 README.md 文件初始化項(xiàng)目這個(gè)地方千萬不要勾選腔呜,因?yàn)樗麜?huì)在遠(yuǎn)程初始化一個(gè)項(xiàng)目出爹,到第5步的時(shí)候,會(huì)造成沖突馅袁,所有域慷,為了避免麻煩,在coding.net上建立Git庫汗销,就建一個(gè)空的犹褒,不啟用README.md文件初始化項(xiàng)目,然后到第5步弛针,才不會(huì)出錯(cuò)叠骑,切記,切記削茁,切記宙枷。
還有一點(diǎn),如果茧跋,按照我上面說的做了慰丛,建立一個(gè)遠(yuǎn)程的coding空的倉庫,第5步可以不用執(zhí)行了瘾杭,
2019-12-25 Merry Christmas
1.進(jìn)入項(xiàng)目文件夾诅病,通過git init 命令,把這個(gè)目錄變成git可以管理的倉庫
git init
2.把文件添加到本地版本庫中,使用git add 命令粥烁,添加到暫存區(qū)贤笆,如果后面接小數(shù)點(diǎn)“.”,意為添加文件夾下的所有文件
git add .
3.使用git commit 命令,把文件提交到本地倉庫讨阻。引號(hào)內(nèi)為提交說明
git commit -m 'first commit'
4.關(guān)聯(lián)到遠(yuǎn)程庫
git remote add orgin 你的遠(yuǎn)程地址
如:
? git remote add origin git@111:1111.git
如果上面步驟寫錯(cuò)了:則
? ? ? git remote rm origin? //刪除origin
? ? ? git remote add origin git@git.oschina.net:yourname/demo.git? //重新添加origin
5芥永、獲取遠(yuǎn)程庫與本地同步合并(如果遠(yuǎn)程庫不為空必須做這一步,否則后面的提交會(huì)失敹鬯薄)
git pull --rebase origin master
6恤左、將最新的修改推送到遠(yuǎn)程倉庫:
git push -u origin master
? ? 備注:origin:遠(yuǎn)程倉庫名字;master:分支
注意:我們第一次push的時(shí)候,加上-u參數(shù),Git就會(huì)把本地的master分支和遠(yuǎn)程的master分支進(jìn)行關(guān)聯(lián)起來,我們以后的push操作就不再需要加上-u參數(shù)了
如果出現(xiàn)類似下面內(nèi)容:
Username for 'https://github.com': shiren1118
Password for 'https://shiren1118@github.com':
To https://github.com/shiren1118/iOS_code_agile.git
![rejected]? ? ? ? master -> master(non-fast-forward)
error: failed to push some refs to'https://github.com/shiren1118/iOS_code_agile.git'
hint: Updates were rejected because the tip of yourcurrent branch is behind
hint: its remote counterpart. Merge the remote changes(e.g. 'git pull')
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push--help' for details.
則輸入命令:git push -u origin master –f 即可搞定問題
二。如何從git服務(wù)器上獲取文件:
如果從在git服務(wù)器所在主機(jī)上的其他賬戶獲取git服務(wù)器上面文件搀绣,則直接用
1. git clone + git倉庫的路徑飞袋,即:gitclone /srv/sample.git/
git remote add origin git@git.dev.tencent.com:iOS_wcj/api_uterm.git
git push -u origin master