Skip to content

Commit 337cab2

Browse files
committed
add for-each-ref in git
1 parent b837d5b commit 337cab2

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

git.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,18 @@ use `git config user.email='[email protected]'` within a project to change the user
3434
email for that project. If that email is associated to another account, the
3535
commit will be credited to them
3636

37+
# clearing branches
38+
39+
use
40+
41+
```
42+
git for-each-ref --format '%(refname:short)' refs/heads | grep -v "master\|main\|develop" | xargs git branch -D
43+
```
44+
45+
notes:
46+
47+
* `for-each-ref` allows a loop over all of the branches
48+
* `'%(refname:short)'` gives the terse branch name
49+
* this is piped into `grep -v` (inverted search) to remove any references in the
50+
list (`master`, `main` or `develop` in this case)
51+
* the result is piped into `xargs` to execute a delete on the git branch name

0 commit comments

Comments
 (0)