How to forcefully delete a remote branch in GitHub?

走远了吗. 提交于 2019-12-03 16:06:27

问题


I have 2 remote branches :

 - pending-issues-in-project
 - new-issues-in-project

I tried to delete pending-issues-in-project like this :
git push origin :pending-issues-in-project, but i got the error :

error: unable to push to unqualified destination: pending-issues-in-project
The destination refspec neither matches an existing ref on the remote nor
begins with refs/, and we are unable to guess a prefix based on the source ref.  
error: failed to push some refs to 'git@github.com:forkedRepo/RepoName.git'

So i thought may be i have deleted pending-issues-in-project branch, but when i run
git branch -a it shows pending-issues-in-project branch in the list.
When i tried same (tried deleting) for new-issues-in-project, it worked.
I have already deleted both branches from local server using git branch -D branchName.

If the error is coming because the branch not exist in repository then why its coming in remote branch list?
and
Is there any way to forcefully deletion of the remote branch?

Thanks for your time.


回答1:


You have to do:

git remote prune origin

to remove that remote tracking branch in your local git repository ( prune removes any branch that does not exist in the remote origin anymore). After that, you will not see it under git branch -a




回答2:


The branch you're seeing is what's called a remote [tracking] branch. It's in your local repository, and it represents the last place you saw that branch in the remote repository. Git uses branches like this so that you don't have to talk to the remote repository every single time you want to deal with it; you just update/fetch once, the remote racking branch is updated, and you can work from that. In your case, the branch in the remote repository is long since deleted; you just need to remove the copy in your local repository.

There are two main ways to delete it:

  • git branch -d -r origin/pending-issues-in-project removes just that branch; and
  • git remote prune origin deletes all such stale remote branches. You can also update at the same time: git remote update --prune origin



回答3:


forgive my clumsy english. i hope you could understand my answer.

  1. the command git push origin :pending-issues-in-project is probably wrong. Maybe you meant: git push origin pending-issues-in-project. It pushes a branch to the github.

  2. If the error is coming because the branch does not exist in repository then why its coming in remote branch list? As git is a distributed version control system, the github's server has a database to store the .git repo and the data you push to it. So, if your use command: git branch -de branchName, it just deletes the local branch and it doesn't interference the github's .git and the data you have push to it.

  3. Is there any way to forcefully deletion of the remote branch? yes, it is possible. the command is:

    git push origin --delete <branchName>
    
  4. If you want to know more about the git version control system's distribute feature, you may find this link useful: git's distributed feature.

    And if you want to know more about deleting a branch on github by git, you can read about it here.



来源:https://stackoverflow.com/questions/8754183/how-to-forcefully-delete-a-remote-branch-in-github

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!