11/21/2023 0 Comments Git delete branch error not y merged![]() ![]() From that moment, you are left with your local feature/X (which you probably don't want any more, since work on feature X is presumably finished), and your remotes/origin/feature/X which is certainly useless because its only purpose was to remember the state of the server's branch.Īnd Git will let you automatically clean up the redundant remotes/origin/feature/X - that's what git fetch -prune does - but for some reason, it doesn't let you automatically delete your own feature/X. Your local repository has a branch remotes/origin/feature/X which means, "This is what the remote told me its feature/X branch was, last time we talked," and finally, the local repository has a branch feature/X which points to your latest commit, and is configured to "track" remotes/origin/feature/X, meaning that you can pull and push to keep them aligned.Īt some point, someone has deleted the feature/X on the remote. Given a tracking branch feature/X, the remote repository (server) will have this branch and call it feature/X. (And recall that "branch" means simply a pointer to a commit.) To understand what's happening, you need to appreciate that, in the situation of tracking branches, you have not one branch, but three. If you want to script a solution, then for-each-ref is your starting point, as in Mark Longair's answer here and this answer to another question, but I can't see a way to exploit it without writing a shell script loop, or using xargs or something. (which is what some of the other answers propose). git branch -d on each orphaned tracking branch.Or, to find them later on, git branch -v (any orphaned tracking branch will be marked ""). Note any remote branches that are reported as deleted.git fetch -prune (or git fetch -p, which is an alias, or git remote prune origin which does the same thing without fetching, and is probably not what you want most of the time).If you want to do this safely, for the use case in the question (garbage-collect tracking branches which have been deleted on the server but still exist as local branches) and with high-level Git commands only, you have to tracking branches and the differences between git remote prune, git prune, git fetch -prune.why you shouldn't parse git branch output in a script.On top of that, most of the suggestions use porcelain commands, whose output is not designed to be parsed by script ("porcelain" refers to the commands intended for human operation scripts should use the lower-level "plumbing" commands). Others do what was asked, but are not simple: all rely on parsing Git output through text-manipulation commands or scripting languages, which may not be present on every system. Some answers are simple, but they don't do what was asked. If "simple" means deleting them all in one go, not fragile, not dangerous, and without reliance on tools that not all readers will have, then the right answer is: no. The question says, "Is there a simple way to delete all tracking branches whose remote equivalent no longer exists?" I wouldn't normally answer a question that already has 16 answers, but all the other answers are wrong, and the right answer is so simple. It will show 'gone' as the remote status. Removes the remote references, when you run git branch -vv The way this works is that after the command git fetch -p The safest way to do this is to use the "plumbing" command git for-each-ref with the interpolation variable %(upstream:track), which will be when the branch is no longer on the remote: git fetch -p & for branch in $(git for-each-ref -format '%(refname) %(upstream:track)' refs/heads | awk '$2 = "" ') do git branch -D $branch done It would be something like the existing command git remote prune origin, but more like git local prune origin. ![]() Now I would like to call some command to delete branches (in this case bug-fix-a, bug-fix-b), which are no longer represented in the remote repository. The Master branch maintainer will merge my changes into master and delete all branches he has already merged. Now I have local branches master, bug-fix-a, bug-fix-b. Now I need to work on bug-fix-a, so I check it out, work on it, and push changes to the remote. Is there a simple way to delete all tracking branches whose remote equivalent no longer exists?
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |