更新時(shí)間:2021-09-27 09:35:47 來(lái)源:動(dòng)力節(jié)點(diǎn) 瀏覽1452次
在大多數(shù)情況下,刪除Git分支很簡(jiǎn)單。您將在本文中學(xué)習(xí)如何在本地和遠(yuǎn)程刪除Git分支。
// delete branch locally
git branch -d localBranchName
// delete branch remotely
git push origin --delete remoteBranchName
Git 存儲(chǔ)庫(kù)具有不同的分支是很常見(jiàn)的。它們是處理不同功能和修復(fù)的好方法,同時(shí)將新代碼與主代碼庫(kù)隔離。
Repos 通常有一個(gè)main主代碼庫(kù)的分支,開(kāi)發(fā)人員會(huì)創(chuàng)建其他分支來(lái)處理不同的功能。
一旦完成一個(gè)功能的工作,通常建議刪除分支。
Git 不會(huì)讓你刪除你當(dāng)前所在的分支,所以你必須確保簽出一個(gè)你沒(méi)有刪除的分支。例如:git checkout main
刪除一個(gè)分支git branch -d<branch> 。
例如: git branch -d fix/authentication
-d僅當(dāng)分支已被推送并與遠(yuǎn)程分支合并時(shí),該選項(xiàng)才會(huì)刪除該分支。-D如果您想強(qiáng)制刪除分支,即使它還沒(méi)有被推送或合并,請(qǐng)改用。
該分支現(xiàn)在已在本地刪除。
這是遠(yuǎn)程刪除分支的命令:git push<remote> --delete .
例如: git push origin --delete fix/authentication
現(xiàn)在該分支已被遠(yuǎn)程刪除。
您還可以使用這個(gè)較短的命令遠(yuǎn)程刪除分支: git push<remote> :
例如: git push origin :fix/authentication
如果您收到以下錯(cuò)誤,則可能意味著其他人已經(jīng)刪除了該分支。
error: unable to push to unqualified destination: remoteBranchName The destination refspec neither matches an existing ref on the remote nor begins with refs/, and we are unable to guess a prefix based on the source ref. error: failed to push some refs to 'git@repository_name'
git fetch -p
該-p標(biāo)志的意思是“修剪”。獲取后,遠(yuǎn)程不再存在的分支將被刪除。
通過(guò)上述相信大家已經(jīng)掌握了在本地和遠(yuǎn)程刪除Git分支的方法,大家要想了解更多相關(guān)知識(shí),可以查看動(dòng)力節(jié)點(diǎn)的Git教程,里面有更多知識(shí)可以在線學(xué)習(xí),希望對(duì)大家有所幫助。
0基礎(chǔ) 0學(xué)費(fèi) 15天面授
有基礎(chǔ) 直達(dá)就業(yè)
業(yè)余時(shí)間 高薪轉(zhuǎn)行
工作1~3年,加薪神器
工作3~5年,晉升架構(gòu)
提交申請(qǐng)后,顧問(wèn)老師會(huì)電話與您溝通安排學(xué)習(xí)
初級(jí) 202925
初級(jí) 203221
初級(jí) 202629
初級(jí) 203743