删除远程分支不会从GitHub中删除(deleting remote branch does not remove from GitHub)

编程入门 行业动态 更新时间:2024-10-28 09:20:11
删除远程分支不会从GitHub中删除(deleting remote branch does not remove from GitHub)

我有一个本地分支,说hotfix 。 我把它放在GitHub上使用

$ git push -u origin hotfix

然后在合并分支后,我想删除它。 所以我输入

$ git branch -d hotfix

它会在本地删除分支。 但是,远程分支仍在GitHub上。 当然,当我看到我的远程分支时,

$ git branch -r origin/HEAD -> origin/master origin/hotfix origin/master

hotfix仍在那里。 那么我试试吧

$ git branch -r -d origin/hotfix $ git branch -r origin/HEAD -> origin/master origin/master

正如预期的那样, hotfix已经消失了。

但后来我去GitHub看看我的分支机构,还有hotfix ! 如何通过命令行从GitHub中删除远程hotfix ,而无需在浏览器中导航到GitHub并使用网站UI删除它?

I have a local branch, say hotfix. I put it up on GitHub using

$ git push -u origin hotfix

Then after merging the branch, I want to delete it. So I type

$ git branch -d hotfix

which deletes the branch locally. However, the remote branch is still on GitHub. Of course when I look at my remote branches,

$ git branch -r origin/HEAD -> origin/master origin/hotfix origin/master

hotfix is still there. So then I try

$ git branch -r -d origin/hotfix $ git branch -r origin/HEAD -> origin/master origin/master

and hotfix is gone, as expected.

But then I go to GitHub and look at my branches, and hotfix is still there! How can I delete the remote hotfix from GitHub via the command line, without having to navigate to GitHub in my browser and delete it using the Website UI?

最满意答案

你需要推送删除:

git push origin --delete hotfix

(任何git branch命令只对你的本地仓库有影响,而不是GitHub远程仓库)

有关详细信息,请参阅“ 如何在本地和远程删除Git分支? ”。

git branch -d -r只删除远程跟踪分支 ,即本地仓库的remotes/origin命名空间中存在的分支。 GitHub(实际的远程仓库)永远不会被通知。

您已“成功”删除的是“远程跟踪分支”,它位于您的本地仓库中,用于记录您从该分支的上游仓库获取的最后一个SHA1:“远程跟踪分支”是什么。

正确的顺序是:

git push origin --delete hotfix git remote update --prune origin

这将删除GitHub仓库上的hotfix分支,然后删除您的仓库中任何过时的远程跟踪分支。

You need to push that deletion:

git push origin --delete hotfix

(any git branch command would only have an effect on your local repo, not the GitHub remote one)

See more at "How to delete a Git branch both locally and remotely?".

A git branch -d -r only deletes a remote tracking branch, that is branches existing in the remotes/origin namespace of your local repo. GitHub (the actual remote repo) is never notified.

What you have "successfully" deleted is the "remote tracking branch" which is in your local repo and is meant to record the last SHA1 that you fetched from the upstream repo for that branch: that what a "remote tracking branch" is.

The correct sequence is:

git push origin --delete hotfix git remote update --prune origin

That will delete the hotfix branch on the GitHub repo, and then delete any obsolete remote tracking branch in your repo.

更多推荐

本文发布于:2023-08-06 03:20:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1444031.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:分支   GitHub   deleting   remove   branch

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!