We can use git for-each-ref to list all branches and their upstream’s branch’s status in our desired format: $ git for-each-ref -format '%(refname) %(upstream:track)' It so happens that the git for-each-ref command lets us specify its output format, neatly circumventing the aforementioned problems. The output can be modified by the user.See this blog post by Junio C Hamano (git maintainer). The output could change in the future.However, this is problematic for the following reasons: A naive approach would be to parse the aforementioned output of git branch -v. The first step in our automation is to identify the branches to delete. But what if there are many of these branches? Things would get tedious quickly, so let’s try to automate this! Identifying the gone branches Our only option is to manually delete them through git branch -d. Unfortunately, git does not have built-in functionality to cleanup these local branches. This indicates that these branches are indeed tracking remote branches that have been deleted. There are three local branches, of which two ( fix-typo and grammar-fix) are marked with. Let’s see if we have local branches that are tracking deleted branches: $ git branch -vįix-typo 7b57d4f Fix typo in README In this case, three remote branches were deleted. To identify these branches, we first have to cleanup (prune) the remote’s branches: $ git fetch -p When using git, local branches can track remote branches that no longer exist (the remote branch is gone).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |