在git中,可以使用「git push origin --delete 分支名稱」語句來刪除遠端分支;在刪除遠端分支時,同名的本機分支並不會被刪除。
![git如何刪除遠端分支](https://img.php.cn/upload/article/202106/30/2021063013542178802.jpg)
本文操作環境:Windows7系統,git2.30.0版本,Dell G3電腦。
刪除遠端分支: git push origin --delete [branchname]
![1625032408103116.png git如何刪除遠端分支](https://img.php.cn/upload/image/236/462/686/1625032408103116.png)
提示刪除了一個名為201804019-test-files 的分支,
注意: 在刪除遠端分支時,同名的本機分支並不會被刪除,所以還需要單獨刪除本機同名分支
如果發生下列錯誤:
# error: unable to delete 'origin/xxxxxxxx-fixbug': remote ref does not exist
error: failed to push some refs to 'git@github.com:xxxxxxxx/xxxxxxxxxx.git'
##解決方案: git checkout xxxxx-fixbug 切換到目前分支上, 然後再進行git push --delete origin origin/xxxxx-fixbug
此時將不會再發生錯誤。
擴充資料:
2、檢視本機分支:git branch
![git如何刪除遠端分支](https://img.php.cn/upload/article/000/000/062/367aefb2be3d57accd15173cd9b043d3-0.png)
前面有*號的是目前分支
3 、刪除本地已合併的分支: git branch -d [branchname] 某些情況下可以用git branch -D [branchName] (使用時應注意是否已合併)
![git如何刪除遠端分支](https://img.php.cn/upload/article/000/000/062/367aefb2be3d57accd15173cd9b043d3-1.png)
提示刪除了一個名為list的本機分支
4、建立分支:git branch [branchname]
需要注意,建立分支時,不會有什麼提示。
5、 看全部分支(包含本地和遠端) :git branch -a
6、根據指定版本號建立分支: git checkout -b branchName commitId
#7、清理本地無效分支(遠端已刪除本地沒刪除的分支): git fetch -p
8、如果分支太多,還可以用此命令進行分支模糊查找: git branch | grep 'branchName'
git tag 刪除本地tag 和永久刪除遠端tag防止恢復-->
#推薦(免費):Git
以上是git如何刪除遠端分支的詳細內容。更多資訊請關注PHP中文網其他相關文章!