Back to TILs

Git - Limpando o repositório

Date: 2019-12-05Last modified: 2022-10-07

Para listar todos os branch locais que já formam mergeados no dev:

git branch --merged dev
  ajuste-cabecalho-inclui-guarda-de-formatacao
  dev
  fix-270B
  fix-86
  fix-gitignore
  fix-wakeup
  hotfix-import-faltando
* test-naming-service
  testar-xml-gerado-contra-dtd
  teste-funcional
  teste-funcional-com-geracao-de-screenshot
  update-documentation-from-testlink

Nota: O branch marcado com * é o branch atual e não deve ser removido se estiver dentro dele.

$ git branch --merged dev | egrep -v "\*"
  ajuste-cabecalho-inclui-guarda-de-formatacao
  dev
  fix-270B
  fix-86
  fix-gitignore
  fix-wakeup
  hotfix-import-faltando
  testar-xml-gerado-contra-dtd
  teste-funcional
  teste-funcional-com-geracao-de-screenshot
  update-documentation-from-testlink

Passando esta lista para um xargs fica fácil executar o git branch -d para cada um dos branches mergeados.

$ git branch --merged dev | egrep -v "\*" | xargs git branch -d
Deleted branch ajuste-cabecalho-inclui-guarda-de-formatacao (was 712f81f5).
Deleted branch dev (was d4ab4ffd).
Deleted branch fix-270B (was 93b8a3c2).
Deleted branch fix-86 (was 65a930a7).
Deleted branch fix-gitignore (was 459db686).
Deleted branch fix-wakeup (was eda4a648).
Deleted branch hotfix-import-faltando (was d17fe5ae).
Deleted branch testar-xml-gerado-contra-dtd (was 1d3b0381).
Deleted branch teste-funcional (was 0967bcdd).
Deleted branch teste-funcional-com-geracao-de-screenshot (was 0967bcdd).
Deleted branch update-documentation-from-testlink (was cae58772).

Referências