Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the most proper way to remove an already deleted branch from tab-completion history?

I can't exactly remember the events that led me to my current scenario, but it happened something similar to this:

  • had a branch named 2-dev-inprogress
  • changed branch name of 2-dev-inprogress to 2-dev-wip using:
    • git branch -mv 2-dev-inprogress 2-dev-wip

My problem is that when i am in another branch and want to checkout 2-dev-wip by using tab-completion (as usual), it only completes 2-dev-, and gives me two options:

  • 2-dev-inprogress
  • 2-dev-wip

Anybody out there know some specific surgery to remove that 2-dev-inprogress branch from tab-completion history? Only thing I've tried so far is commenting out source ~/.git-completion.bash in my .bash_profile and restart iTerm, but no luck. I also snooped around the .git directory, but got scared thinking I would fudge something up beyond repair.

like image 486
RudyOnRails Avatar asked Nov 13 '12 20:11

RudyOnRails


People also ask

How do I remove old branches in git?

The easiest way to delete local Git branches is to use the “git branch” command with the “-d” option. The “-d” option stands for “–delete” and it can be used whenever the branch you want to clean up is completely merged with your upstream branch. $ git branch -d release Deleted branch feature (was bd6903f).

Does deleting a git branch remove history?

The commits will still be retained in the repository and it is possible to recover them immediately after the delete, but eventually they will be garbage collected. Thanks for the answer.

How do I delete a deleted local branch?

Deleting Local Branches First, use the git branch -a command to display all branches (both local and remote). Next, you can delete the local branch, using the git branch -d command, followed by the name of the branch you want to delete.

How do I delete a branch?

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.


2 Answers

The accepted answer makes sense, but did not work in my situation. If the remote branch no longer exists, then you may additionally need to prune. I used Seth Robertson's suggestion to clean up my system and get rid of many branches all at once: git remote | xargs -n1 git remote prune. This can happen if another person deleted the remote branch(es) or in my case if you did it from another machine.

like image 174
sage Avatar answered Oct 07 '22 09:10

sage


Do you still have a remote branch named 2-dev-inprogress? If so you have to remove this branch or prevent git-completion of remote branches by commenting out the remote checks in /etc/bash_completion.d/git

like image 1
Michael Avatar answered Oct 07 '22 10:10

Michael