Git에서 여러 브랜치를 삭제하는 방법

주재성·2023년 2월 2일
0
post-thumbnail
  1. Open the terminal
  2. Type in git branch | grep "<pattern>" for a preview of the branches that will be deleted.
  3. Type in git branch | grep "<pattern>" | xargs git branch -D

Replace the with a regular expression to match your branch names and that’s it.

ex.

jaesungju@DT-jaesung:~/test(master)$ git branch
  arcpatch-D10866
  branch_test
  branch_test2
* master

jaesungju@DT-jaesung:~/test(master)$ git branch | grep "branch_test"
  branch_test
  branch_test2

jaesungju@DT-jaesung:~/test(master)$ git branch | grep "branch_test" | xargs git branch -D
Deleted branch branch_test (was 01c21cd71).
Deleted branch branch_test2 (was 01c21cd71).

jaesungju@DT-jaesung:~/test(master)$ git branch
  arcpatch-D10866
* master

Use grep -v if is not found in the branch.
-v, --invert-match select non-matching lines

jaesungju@DT-jaesung:~/test(master)$ git branch
  a
  b
  c
  d
* master

jaesungju@DT-jaesung:~/test(master)$ git branch | grep "^*"
* master

jaesungju@DT-jaesung:~/test(master)$ git branch | grep -v "^*"
  a
  b
  c
  d

-- deleting all branches
jaesungju@DT-jaesung:~/test(master)$ git branch | grep -v "^*" | xargs git branch -D
Deleted branch a (was 01c21cd71).
Deleted branch b (was 01c21cd71).
Deleted branch c (was 01c21cd71).
Deleted branch d (was 01c21cd71).

jaesungju@DT-jaesung:~/test(master)$ git branch
* master

reference.
https://medium.com/@rajsek/deleting-multiple-branches-in-git-e07be9f5073c

0개의 댓글