刪除遠端分支· Git | Git delete branch
在"上傳分支"[1]教過如何使用gitpush添加遠端的分支接下來我們想要把分支bugFix刪除使用gitpush
在 "上傳分支"[1] 教過如何使用 git push 添加遠端的分支
接下來我們想要把分支 bugFix 刪除
使用 git push <remote name> :<branch name> 刪除遠端分支這裡一樣是用 git push,只要在分支名稱的前面多加一個 :(冒號)
使用 Github 網頁介面刪除分支除此之外,也可以透過 Github 的網頁介面來操作
在我們刪除完 bugFix 分支之後,我們查看我們本機端的狀況,發現 remotes/github/bugFix 並沒有消失
即使我們用了 git remote update 之後,結果還是一樣,本機端的分支依舊無法跟遠端同步
使用 git remote show <remote name> 查看更多關於 remote 的資訊 refs/remotes/github/bugFix stale (use git remote prune to remove)這行的意思是說,遠端的 bugFix 已經過期了,請用 git remote prune 將它移除
使用 git remote prune <remote name> 刪除 remote 底下所有過時的分支 $ git remote prune github這個指令也可以用 git fetch 來代換
$ git fetch -p $ git fetch --prune # 同上 使用 git remote update -p 同步遠端分支,並且移除過時的遠端分支Git 可能是為了避免遠端的分支被刪,所以才預設同步時保留過時的分支
但是為了要刪這個遠端的分支,要先用 git remote show 檢查,再用 git remote prune 刪除,這樣實在太麻煩了
git remote update -p 一次幫你全部搞定
參數 -p 等同於 --prune
我們把分支 bugFix 再 push ...