Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deleting a remote branch

Tags:

git

branch

When I perform branch -a:

$ git branch -a
* master
 remotes/origin/HEAD -> origin/master
 remotes/origin/hello
 remotes/origin/master

And then I remove the branch:

$ git branch -r -D origin/hello
Deleted remote branch origin/hello (was c0cbfd0).

Now I see:

$ git branch -a
* master
 remotes/origin/HEAD -> origin/master
 remotes/origin/master

The branch "hello" has been removed. But when I fetch:

$ git fetch
From localhost:project
 * [new hello]      hello     -> origin/hello

$ git branch -a
* master
 remotes/origin/HEAD -> origin/master
 remotes/origin/hello
 remotes/origin/master

I'm so confused.
I think it has been removed, but it is still there.

like image 728
user1648059 Avatar asked Sep 05 '12 06:09

user1648059


2 Answers

You need to remove it from the remote with the following command:

git push origin --delete hello

When you are running git branch -rd origin/hello you are deleting your local branch only. The code above removes it from the origin repo.

like image 69
Nic Avatar answered Oct 04 '22 07:10

Nic


To delete a remote branch, use

git push origin :remotebranch

Everything else operates on the local repository only. In more recent versions of git, you can also

git push origin --delete remotebranch

As per the documentation, --delete means the same "as prefixing all refs with a colon".

If you are wondering about meaning of the :, it follows the standard syntax for push. Usually, you would write

git push origin localbranch:remotebranch

but here, you replace localbranch with "nothing", effectively deleting the remote branch.

like image 40
Urs Reupke Avatar answered Oct 04 '22 06:10

Urs Reupke