Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git says remote ref does not exist when I delete remote branch

Tags:

git

People also ask

What happens when you delete a remote branch in git?

Note that deleting the remote branch X from the command line using a git push will also remove the local remote-tracking branch origin/X , so it is not necessary to prune the obsolete remote-tracking branch with git fetch --prune or git fetch -p . However, it wouldn't hurt if you did it anyway.

How do I force delete a remote branch?

Deleting remote branches 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 .

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.


The command git branch -a shows remote branches that exist in your local repository. This may sound a bit confusing but to understand it, you have to understand that there is a difference between a remote branch, and a branch that exists in a remote repository. Remote branches are local branches that map to branches of the remote repository. So the set of remote branches represent the state of the remote repository.

The usual way to update the list of remote branches is to use git fetch. This automatically gets an updated list of branches from the remote and sets up remote branches in the local repository, also fetching any commit objects you may be missing.

However, by default, git fetch does not remove remote branches that no longer have a counterpart branch on the remote. In order to do that, you explicitly need to prune the list of remote branches:

git fetch --prune

This will automatically get rid of remote branches that no longer exist on the remote. Afterwards, git branch -r will show you an updated list of branches that really exist on the remote: And those you can delete using git push.

That being said, in order to use git push --delete, you need to specify the name of the branch on the remote repository; not the name of your remote branch. So to delete the branch test (represented by your remote branch origin/test), you would use git push origin --delete test.


The meaning of remotes/origin/test is that you have a branch called test in the remote server origin. So the command would be

git push origin --delete test

There's a shortcut to delete the branch in the origin:

git push origin :<branch_name>

Which is the same as doing git push origin --delete <branch_name>


  1. get the list of remote branches
git fetch # synchronize with the server
git branch --remote # list remote branches
  1. you should get a list of the remote branches:
origin/HEAD -> origin/master
origin/develop
origin/master
origin/deleteme
  1. now, we can delete the branch:
git push origin --delete deleteme