Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you delete a remote git branch "properly", a.k.a. updating the remote branch list for all users?

Tags:

git

branch

I'm trying to delete a remote git branch, however the process isn't "fully" deleting the branch as I'd expect.

Let's say for example I'm deleting a branch called mybranch. To do this, I run the following command,

git push origin :mybranch 

This removes the branch as expected, and if I do git branch -a it no longer appears on the list locally or remotely.

The problem I'm having is if I go another person's machine who did a git pull while the branch existed, and they perform a git branch -a, it's still in their list as a remote branch.

We've tried multiple commands, pull, gc, prune, but nothing is updating this list and removing the remote branch.

Is there a command to sync (what I can only assume is) the local cache of the remote branches list, and remove any remote branches that no longer exist?

like image 448
Stephen Melrose Avatar asked Mar 03 '11 15:03

Stephen Melrose


People also ask

How do I delete a remote git branch?

Steps to delete remote Git branchesIssue the git push origin –delete branch-name command, or use the vendor's online UI to perform a branch deletion. After the remote branch is deleted, then delete the remote tracking branch with the git fetch origin –prune command.

How do I delete all remote branches?

Let's break this command: First we get all remote branches using the git branch -r command. Next, we get the local branches not on the remote using the egrep -v -f /dev/fd/0 <(git branch -vv | grep origin) command, Finally we delete the branches using the xargs git branch -d command.

How do I delete a branch in Git lab?

GitLab delete remote branch overview Switch to the master branch via the 'git checkout' command; Delete the branch locally; Push to origin with the –delete flag; and. Verify local and remote tracking branches are deleted with a 'branch listing' command.

How do you update a remote branch?

Forces an update of the remote branch after rewriting the history locally. Use git push -f to force update the remote branch, overwriting it using the local branch's changes. This operation is necessary anytime your local and remote repository diverge.


2 Answers

Until they update their remotes, their git will have no knowledge of what's happened on the repository. Once they've done an update (via git fetch or git remote update), git remote show origin will correctly show that they have local tracking branches for branches that no longer exist upstream. At that point, git remote prune can be used to remove the stale local branches.

like image 118
jamessan Avatar answered Sep 18 '22 13:09

jamessan


To remove any remote-tracking branches which no longer exist on the remote.

git fetch -p 
like image 39
user665846 Avatar answered Sep 21 '22 13:09

user665846