[Git] Command to Bulk Delete Merged Remote Branches

Tadashi Shigeoka ·  Fri, January 20, 2017

I’ll introduce a command to bulk delete merged remote branches in Git.

Git | ギット

Bulk Delete Command for Merged Remote Branches

git branch --remote --merged master | \\
grep -v -e master -e release -e staging | \\
sed -e 's% *origin/%%' | \\
xargs -I% git push --delete origin %

This assumes that master, release, and staging branches are excluded from deletion.

Synchronizing Remote Branches After Deletion

Even if someone else deletes remote branches, the remote branch information remains in your local branches.

You can synchronize remote branch information with the following command:

git remote prune origin

Alternatively, you can synchronize by adding the —prune option like:

git fetch --prune

or

git pull --prune

Reference Information

That’s all from the Gemba.