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?
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.
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.
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.
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.
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.
To remove any remote-tracking branches which no longer exist on the remote.
git fetch -p
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With