![]() ![]() The process of passing on the output of one command to to another is made possible by the use of | (pipeline). xargs git branch -D - passes the filtered branch names to the git command git branch -D.grep -v 'master': Filter the branch list and returns only non-matching lines to the string master. grep -v '^*' - filters out the branch starting with * (current branch, which was master) To delete all local Git branches except for master, you can use the following command: git branch grep -v 'master' xargs git branch -D Let’s breakdown the command: git branch: List all local branches.We use three commands to accomplish what we want to achieve. Git automatically expands the serverfix branchname out to refs/heads/serverfix:refs/heads/serverfix, which means, Take my serverfix local branch and push it. ![]() Removes all merged remote branches except default branches: master. Git has a command for deleting branches ( git branch -D or git branch -d ), but it does not provide an option for specifying "except this branch or these branches". Collection of excluded from removing branches. This command will do that for you: $ git branch | grep -v '^*' | xargs git branch -d ![]() Now, what if you want to be a little less adventurous and delete only branches that have been merged to master? It will delete all the local branches, whether they have been merged to master or not. Then run this command: $ git branch | grep -v '^*' | xargs git branch -D Removing them one by one would be a cumbersome task. There’s a Default branch dropdown list near the top of the screen. Remove all git branches except master Published: 2020.12.20 1 minute read After working on a project for a while, it’s easy to end up with a lot of legacy branches that are not needed anymore. Click on the 'Branches' tab on the left hand side. You need to go to the GitHub page for your forked repository, and click on the Settings button. If you want to delete all the local branches except the master branch, here's what you can do.įirst, make sure you are on master: $ git checkout master As explained in 'Deleting your master branch' by Matthew Brett, you need to change your GitHub repo default branch. That's when it is time for a branch clean up! A few branches may be fine, but sometimes they can pile up and lead to an unacceptably large number of branches. How to delete all local git branches except master #ĭuring the normal course of a project, git repositories can accumulate a number of branches locally. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |