All the remote branches are visible as remotes in my local git repository after a git fetch.
How to selectively remove the remote branches in my local repository (not in the remote repository)?
You'll often need to delete a branch not only locally but also remotely. To do that, you use the following command: git push <remote_name> --delete <branch_name>. The branch still exists locally, though.
Deleting a branch LOCALLY Delete a branch with git branch -d <branch> . The -d option will delete the branch only if it has already been pushed and merged with the remote branch. Use -D instead if you want to force the branch to be deleted, even if it hasn't been pushed or merged yet. The branch is now deleted locally.
Deleting Remote Branches Unlike local branches, you can't delete a remote branch using the git branch command. However, you need to use the git push --delete command, 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 .
I had a slightly different but similar issue, but the solution might be useful to others who stumble on this question...
I noticed that my local repository still had remote branches that no longer existed on the remote, so I wanted to remove them. The solution is simply to fetch with the --prune
(or -p
) option:
git fetch --prune
git branch -r -d remote/branch
You also need to reconfigure fetch to avoid fetching this branch again later
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