Skip to content Skip to sidebar Skip to footer

Git Delete All Local Branches Except Current

Git Delete All Local Branches Except Current. It will delete all the local branches, whether they have been merged to master or not. Rename the temporary branch to master:

Improving shell workflows with fzf Sebastian Jambor's blog
Improving shell workflows with fzf Sebastian Jambor's blog from seb.jambor.dev

When it contains commits that haven't been merged into any other local branches or pushed to a remote repository. Do git push origin :heads/$line; Windows for /f tokens=* %%g in ('git branch ^|.

To Clear All Your Local Branches (Except Master And Current Branch), Run Below At Your Git Repo:


So, the solution is to come up with a single command that will do it all at once for the current repo. Delete all local branches except for “master” just rename the branch name you are using in the grep command. The result is shown in the graphic below:

The Branches In Red Are The Remote Branches I.e.


The laziest way to delete all unused branches safely except master: # undo the last commit but keep changes. The command to delete all branches except master is:

When It Contains Commits That Haven't Been Merged Into Any Other Local Branches Or Pushed To A Remote Repository.


Do git push origin :heads/$line; In case you want to restore deleted branch, see here Delete all branches except master and develop.

This Will Do The Same, Leaving Both.


It will delete all the local branches, whether they have been merged to master or not. First, make sure you are on master: Windows for /f tokens=* %%g in ('git branch ^|.

Replace Branchtoskip_Deletion With The Branch Name You Don't Want To Delete And This Command Will Remove All The Local Branches Except The Mentioned One.


Forcefully update the remote repository: To use the same command in windows we have to install some utilities. Delete all remote branches, except master.

Post a Comment for "Git Delete All Local Branches Except Current"