曾经纠结于在github.com上开了太多分支导致分支过于混乱。一直在寻找删除远端分支的方法,可是网上搜到的方法都不好用。

   无意间犯的一个错误导致github.com的项目上的一个分支被删除,才发现删除github.com分支的方法。希望能够为大家提供帮助。

   思路:

   新建一个空的版本库,直接把空的版本库push到github.com的某个分支上。这个分支就会被自动删除。

   代码:

 
  
  1. remote_repo="https://github.com/lexdene/Dlut-Game-Platform.git" #这是我想删除分支的仓库地址

  2. remote_branch="libapi" #这是我想删除的远端仓库分支的名字

  3. mkdir /tmp/git-empty

  4. cd /tmp/git-empty

  5. git init

  6. git push $remote_repo :$remote_branch #有个冒号不能省略

   全文完。



# 更新

git branch -d -r $remote_branch

git push remote_name --delete branch_name