使用場景:新建一個(gè)git倉儲(chǔ)并與遠(yuǎn)程關(guān)聯(lián)
1.初始化一個(gè)新的空的git倉儲(chǔ),并在倉儲(chǔ)下做一些改動(dòng)
mkdir gitDir
cd gitDir/
git init
touch file
git status #查看當(dāng)前未提交的改動(dòng)
git add file
git commit -m "新建文件file" #將本次改動(dòng)提交到本地倉庫
2.在git上或者碼云上新建一個(gè)倉儲(chǔ)A
3.在本地倉庫添加遠(yuǎn)程倉庫A并將本地的master分支跟蹤到遠(yuǎn)程的分支
git remote add test https://gitee.com/neimenggudaxue/test.git #git remote add 遠(yuǎn)程倉儲(chǔ)名名稱唯一即可 遠(yuǎn)程倉儲(chǔ)地址
git remote -v # 查看關(guān)聯(lián)的所有的遠(yuǎn)程倉儲(chǔ)名稱及地址
git remote #查看所有的遠(yuǎn)程倉儲(chǔ)名稱
git push test master -f #提交本地倉儲(chǔ)分支(master) 給遠(yuǎn)程倉儲(chǔ)(test)分支(master) 此處是強(qiáng)制提交,
git status # 查看當(dāng)前未提交的內(nèi)容,此時(shí)應(yīng)該為空
使用場景:A倉儲(chǔ)下代碼提交至B倉儲(chǔ)
1.克隆倉儲(chǔ)A的代碼到本地并修改
2.查看當(dāng)前遠(yuǎn)程倉儲(chǔ),結(jié)果是倉儲(chǔ)A git remote -v
3.刪除當(dāng)前遠(yuǎn)程分支(也可以不刪) git remote remove A
4.新增遠(yuǎn)程倉儲(chǔ)Bgit remote add repository_B URL #URL為倉儲(chǔ)B的地址
5.提交本次修改至本地倉儲(chǔ)
git add .
git commit -am "提交修改至本次倉儲(chǔ)"
6.提交本地倉儲(chǔ)到遠(yuǎn)程倉儲(chǔ)repository_B的master分支
git push repository_B master -f #需強(qiáng)制提交,因遠(yuǎn)程分支的readMe文件與本地的有沖突
PS:均是實(shí)踐產(chǎn)生的結(jié)果,希望自己以后多嘗試
需學(xué)習(xí)命令:
git remote
git remote -v
git remote add repositiry_name repository_url
git remote remove repositiry_name
git push repositiry_name branch -f
git status