Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I delete a remote branch in Git? [duplicate]

Tags:

git

I created a branch notmaster to commit as well as push some changes. When I was finished with that branch, I merged the changes back into master, pushed them out, and then deleted the local notmaster.

$ git branch -a * master   remotes/origin/master   remotes/origin/notmaster 

Is there anyway to delete the remote notmaster?


A little more clarity, with the solution from Ionut:

The usual method failed for me:

$ git push origin :notmaster error: dst refspec notmaster matches more than one. 

That's because I had a tag with the same name as the branch. This was a poor choice on my behalf and caused the ambiguity. So in that case:

$ git push origin :refs/heads/notmaster 
like image 807
chrisaycock Avatar asked Nov 11 '10 22:11

chrisaycock


People also ask

How do I remove a remote git branch?

To delete a remote branch, you can't use the git branch command. Instead, use the git push command with --delete flag, followed by the name of the branch you want to delete. You also need to specify the remote name ( origin in this case) after git push .

How do you clean a remote branch?

In order to clean up remote-tracking branches while fetching, use the “git fetch” command with the “–prune” option. Alternatively, you can simply use the “-p” shortcut instead of typing “prune” every time.

Is it okay to delete a branch in your remote repository?

It is safe to delete your local branch after you pushed your changes to your own remote repository. The pull request is unrelated to this, because it is simply a request to the maintainers of the original repository to merge your changes back into their code base.


2 Answers

git push origin :notmaster, which basically means "push nothing to the notmaster remote".

like image 199
Ionuț G. Stan Avatar answered Sep 20 '22 21:09

Ionuț G. Stan


I had the same issue. I had both a branch and a tag named 3.2. That's why it says there's more than one match:

git error: dst refspec 3.2 matches more than one. 

Here's how to delete the branch:

git push origin :heads/3.2 

And here's how to delete the tag:

git push origin :tags/3.2  
like image 40
Oleg Abrazhaev Avatar answered Sep 21 '22 21:09

Oleg Abrazhaev