Nest all content into snippets

This commit is contained in:
Angelos Chalaris
2023-05-07 16:07:29 +03:00
parent 2ecadbada9
commit 6a45d2ec07
1240 changed files with 0 additions and 0 deletions

View File

@ -0,0 +1,33 @@
---
title: Delete merged branches
type: snippet
language: git
tags: [repository,branch]
cover: duck-plants
dateModified: 2021-04-13T21:10:59+03:00
---
Deletes all local merged branches.
- Use `git branch --merged <branch>` to list all branches merged into `<branch>`.
- Use the pipe operator (`|`) to pipe the output and `grep -v "(^\*|<branch>)"` to exclude the current and the target `<branch>`.
- Use the pipe operator (`|`) to pipe the output and `xargs git branch -d` to delete all of the found branches.
```shell
git branch --merged <branch> | grep -v "(^\*|<branch>)" | xargs git branch -d
```
```shell
git checkout master
git branch
# master
# patch-1
# patch-2
# Assuming `patch-1` is merged into master
git branch --merged master | grep -v "(^\*|master)" | xargs git branch -d
git branch
# master
# patch-2
```