12

I deleted a branch with :

git branch -d branch_name

And I pushed, but when I list the branches with :

git branch -avv 

I see that the branch is always present with the name remotes/origin/branch_name.

How can I delete the branch from there?

CKE
  • 1,533
  • 19
  • 18
  • 29
Brahim LAMJAGUAR
  • 1,254
  • 5
  • 19
  • 28
  • You only deleted the branch locally, to delete it in the remote you have to do `git push origin -d branch_name` as well. – Lasse V. Karlsen Aug 22 '18 at 10:12
  • @LasseVågsætherKarlsen But would that remove the local tracking branch as well? At least, I might expect a `git fetch` would be necessary, but maybe not even that would be enough. – Tim Biegeleisen Aug 22 '18 at 10:13
  • 3
    Possible duplicate of [How do I delete a Git branch both locally and remotely?](https://stackoverflow.com/questions/2003505/how-do-i-delete-a-git-branch-both-locally-and-remotely) – evolutionxbox Aug 22 '18 at 10:14
  • @LasseVågsætherKarlsen when I use git push origin -d branch_name I get the following error : error: unable to delete 'branch_name' : remote ref does not exist – Brahim LAMJAGUAR Aug 22 '18 at 10:24

1 Answers1

23

When you delete a branch with git branch -d branch_name you just delete the local one. Push will not affect the status of the remote, so origin/branch_name will remain. If you want to delete it you should do git push <remote_name> --delete <branch_name> as explained in the post suggested as duplicate.

When someone else delete a branch in the remote (origin) a ref to it will be present in your local repository, so after a pull or fetch you will still see origin/branch_name. To delete this ref you have to fetch with --prune.

git fetch --prune

If you want you can also combine it inside the pull command.

git pull --prune
ErniBrown
  • 1,283
  • 12
  • 25
  • when I use git push --delete I get the following error : error: unable to delete 'branch_name' : remote ref does not exist – Brahim LAMJAGUAR Aug 22 '18 at 12:21
  • 2
    @BrahimLAMJAGUAR the command is correct, for example I tested it with `git push origin --delete branchA`. Please check your command, or check if the branch really exist. Also, please note that `push --delete` was not present in old git version, check your version with `git --version`. If it's an old one you can use `git push :` – ErniBrown Aug 22 '18 at 12:29