更新時間:2021-09-27 09:35:47 來源:動力節點 瀏覽1335次
在大多數情況下,刪除Git分支很簡單。您將在本文中學習如何在本地和遠程刪除Git分支。
// delete branch locally
git branch -d localBranchName
// delete branch remotely
git push origin --delete remoteBranchName
Git 存儲庫具有不同的分支是很常見的。它們是處理不同功能和修復的好方法,同時將新代碼與主代碼庫隔離。
Repos 通常有一個main主代碼庫的分支,開發人員會創建其他分支來處理不同的功能。
一旦完成一個功能的工作,通常建議刪除分支。
Git 不會讓你刪除你當前所在的分支,所以你必須確保簽出一個你沒有刪除的分支。例如:git checkout main
刪除一個分支git branch -d<branch> 。
例如: git branch -d fix/authentication
-d僅當分支已被推送并與遠程分支合并時,該選項才會刪除該分支。-D如果您想強制刪除分支,即使它還沒有被推送或合并,請改用。
該分支現在已在本地刪除。
這是遠程刪除分支的命令:git push<remote> --delete .
例如: git push origin --delete fix/authentication
現在該分支已被遠程刪除。
您還可以使用這個較短的命令遠程刪除分支: git push<remote> :
例如: git push origin :fix/authentication
如果您收到以下錯誤,則可能意味著其他人已經刪除了該分支。
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標志的意思是“修剪”。獲取后,遠程不再存在的分支將被刪除。
通過上述相信大家已經掌握了在本地和遠程刪除Git分支的方法,大家要想了解更多相關知識,可以查看動力節點的Git教程,里面有更多知識可以在線學習,希望對大家有所幫助。
0基礎 0學費 15天面授
有基礎 直達就業
業余時間 高薪轉行
工作1~3年,加薪神器
工作3~5年,晉升架構
提交申請后,顧問老師會電話與您溝通安排學習