Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git remote branch deleted, but still it appears in 'branch -a'

Tags:

git

git-branch

Let's say I had a branch named coolbranch in my repository.

Now, I decided to delete it (both remotely and locally) with:

git push origin :coolbranch git branch -D coolbranch 

Great! Now the branch is really deleted.

But when I run

git branch -a 

I still get:

remotes/origin/coolbranch 

Something to notice, is that when I clone a new repository, everything is fine and git branch -a doesn't show the branch.

I want to know - is there a way to delete the branch from the branch -a list without cloning a new instance?

like image 252
yonix Avatar asked Feb 23 '11 17:02

yonix


People also ask

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 .

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 delete a local branch if the remote branch is deleted?

First, use the git branch -a command to display all branches (both local and remote). Next, you can delete the local branch, using the git branch -d command, followed by the name of the branch you want to delete.

Does git pull remove deleted branches?

This is because "git pull" does not remove remote tracking branches for branches deleted from remote repo.


1 Answers

git remote prune origin, as suggested in the other answer, will remove all such stale branches. That's probably what you'd want in most cases, but if you want to just remove that particular remote-tracking branch, you should do:

git branch -d -r origin/coolbranch 

(The -r is easy to forget...)

-r in this case will "List or delete (if used with -d) the remote-tracking branches." according to the Git documentation found here: https://git-scm.com/docs/git-branch

like image 122
Mark Longair Avatar answered Oct 13 '22 10:10

Mark Longair