Git:如何删除远程分支?

Git:如何删除远程分支?

我在 git 上有一个远程分支,我想删除它(remotes/me/ntopng)。

$ git branch -a
* master
  remotes/me/ntopng
  remotes/origin/gh-pages
  remotes/origin/go
  remotes/origin/master

但是当尝试删除它时出现以下情况:

$ git push origin :remotes/me/ntopng
Username for 'https://github.com': Drewshg312
Password for 'https://[email protected]':
remote: Permission to Homebrew/homebrew.git denied to Drewshg312.
fatal: unable to access 'https://github.com/Homebrew/homebrew/': The requested URL returned error: 403

所以我改用https://github.com/Drewshg312/homebrew.git正在做:

git remote set-url origin https://github.com/Drewshg312/homebrew.git 

并得到:

$ git push origin :ntopng
Username for 'https://github.com': Drewshg312
Password for 'https://[email protected]':
To https://github.com/Drewshg312/homebrew.git
 - [deleted]         ntopng

分支仍在那儿

$ git branch -a
* master
  pork
  scirius
  remotes/Drewshg312/hb_custom_formulas
  remotes/me/ntopng                <----- STILL THERE!! WTF???
  remotes/me/pork
  remotes/me/scirius
  remotes/origin/gh-pages
  remotes/origin/go
  remotes/origin/master

那么如何才能彻底删除呢?

答案1

您的原始 URL 是否正确?当前原始 URLHomebrew/homebrew没有ntopng分支。您可能也没有权限向其推送。

如果你打算推送到你的分叉仓库,那么原点应该是https://github.com/Drewshg312/homebrew.git


编辑更新的问题:

正如你在输出中看到的

$ git branch -a
* master
  pork
  scirius
  remotes/Drewshg312/hb_custom_formulas
  remotes/me/ntopng          <----- this is another branch on a remote called 'me'
  remotes/me/pork
  remotes/me/scirius
  remotes/origin/gh-pages
  remotes/origin/go
  remotes/origin/master      <----- no ntopng in origin anymore

上的远程分支origin已被删除。似乎您有多个远程分支。尝试git remote -v看看。要删除远程分支中名为 的分支me,只需执行您对 的操作即可。origin

git push me :ntopng

相关内容