I've deleted some local branches via git branch -d branchname
, but they are still exist in autocomplete (when I put git checkout
, then press tab
key, I see all deleted branches in list).
I've tried to make git gc
and git prune
, but nothing changes.
To completely remove a remote branch, you need to use the git push origin command with a -d flag, then specify the name of the remote branch. So the syntax representing the command for removing a remote branch looks like this: git push origin -d branch-name .
Remove remote Git branch from GitHub or GitLab To do this, you must issue the following Git command to remove a branch from a remote repository: git push origin --delete name-of-branch-to-remove.
TL;DR - the real answer:
$ git remote prune origin
Slightly more details:
git branch -d foo-branch
will fail to delete if foo-branch is not merged into your current branch.
It's also a good idea to clean up old branches on a remote if they've already been merged. You can do this from the commandline by git push origin :foo-branch
.
However, the old "phantom" branch foo-branch will linger for autocompleting git checkout. Apparently git is caching the branches available on the remote. By calling:
$ git remote prune origin
You can clear the local cache of what branches are available on the git remote.
I can reproduce the OP's issue for git 2.2.1 (and probably earlier versions) on OSX.
If you are sure that you do not want the branch, you can remove it from your local and the remote like this:
$ git branch -D branchname
$ git push origin :branchname
Then it will stop appearing in autocomplete results.
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