Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git - how to remove branch from checkout autocomplete

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.

like image 740
user1486054 Avatar asked Mar 03 '14 13:03

user1486054


People also ask

How do I exclude a remote branch?

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 .

How do I disconnect from a branch in git?

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.


2 Answers

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.

like image 52
Rustavore Avatar answered Sep 30 '22 23:09

Rustavore


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.

like image 39
Agis Avatar answered Sep 30 '22 23:09

Agis