I have a remote repository and 2 clones.
I create a branch in one of the clones e.g. test
. I do some work and 2 commits. I merge to master
branch and push -u
the branch.
I do a git pull
in the other clone.
I see both master
and test
.
In the first clone project I do:git origin :test
to delete test
branch on remote repository.test
is deleted on remote repos.
I do git branch -D test
and the test
branch is deleted locally as well.
If I do git branch -a
I get:
*master remotes/origin/master
Now in the second repository I do a git pull
.
On the pull the local test
seems to be deleted but git
seems to "think" that the remote test
branch still exist.
If I do git branch -a
I get:
* master remotes/origin/HEAD -> origin/master remotes/origin/master remotes/origin/test
Why does the deleted test
branch appear as a remote 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.
They're unnecessary. In most cases, branches, especially branches that were related to a pull request that has since been accepted, serve no purpose. They're clutter. They don't add any significant technical overhead, but they make it more difficult for humans to work with lists of branches in the repository.
Local branches are branches on your local machine and do not affect any remote branches. git branch is the command to delete a branch locally. -d is a flag, an option to the command, and it's an alias for --delete .
What Happens If I Delete a Git Branch? When you delete a branch in Git, you don't delete the commits themselves. That's right: The commits are still there, and you might be able to recover them.
The default options for git fetch
(and consequently git pull
) do not prune deleted remote branches. I'm not sure what the logic behind this default is. In any case, to prune deleted remote branches, either fetch with
git fetch -p
or run
git remote prune [-n] <name>
explicitly. With the -n
flag, it will report which branches will be pruned, but not actually prune them. See git-fetch(1) and git-remote(1) for more information.
Try using this command git remote prune origin
. The deleted branch should disappear. This should remove local references to remote branches.
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