Indeed I recently started to use a shell called nushell which is a pretty powerful yet simple cross-platform shell. You can find on Stackoverflow some posts like this one that show different solutions using bash that work perfectly but I thought it would be interesting to try to script that using another shell. Now we only need a script to associate output and input of these two commands in order to automate the deletion. We know how to identify the outdated branches but we need a command to delete them which is the git branch -D command. These branches correspond to the outdated branches we want to delete. The command git branch -vl (which lists in a verbose way the local git branches) gives us an interesting view as it shows the branches for which the remote has been deleted specifying a for them. If I take my blog repository as an example I have a bunch of branches: some that could be useful (articles I have started to write but did not finish yet and I don't know if I will one day □) and some that are already merged into my master branch through a PR. But as it's Azure DevOps which took care of merging them (sometimes with a squash) I cannot use the git branch -merged command. Git commands to identify and delete outdated branches.Īs my outdated branches are already removed from my remote (thanks to git fetch -prune) it should not be too complicated to use some git commands to guess which branches are not useful anymore. Nevertheless, this does not delete the local version of the feature branch thus our problem: over the time if we do not think of deleting all these outdated branches, they become too many and we don't even know which branch should be kept or not. Once that done, I can do a git fetch -prune on my laptop to have the feature branch removed from the remote of my local repository (by the way, I recommend you to directly set the fetch command to prune by default in your git config □). When a pull request is approved and we decide to complete it, Azure DevOps takes care of automatically merging the associated feature branch into master and deleting it from the repository. However, each week we are creating a lot of branches that need to be deleted as once merged we no longer need to have them. These practices allow us to keep a good quality in our code base, not to mess with our git repositories and ensure the main branch always build.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |