Olá!
Bem, muitas vezes no dia-a-dia com o git, você abre um branch para a feature, termina, faz merge na master e pronto! Está entregue. O problema é que com isso, seu git fica cheio de branches que são, digamos: INÚTEIS. E claro que com o tempo esses branches se reproduzem como coelhos.
Como fazer para apagar todos esses branches? Você deve ter percebido que apenas um git branch -D meu-branch
só apaga o branch no seu computador, e em nenhum remote.
Fácil, é só fazer o código git push origin :meu-branch
, que além de ser nem um pouco claro (WTF?), te obriga a fazer isso um a um. Se forem muitos branches, babau!
Mas agora seus problemas acabaram! Chegou o git-sweep! Olha lá o repositório... É um projeto para fazer o delete de todos os branches que já estão merged, ou seja, que não tem nenhum commit ahead.
É um projeto em Python, portanto terá que ter ele instalado na máquina e rodar:
$ pip install git-sweep || easy_install git-sweep
Depois disso é só rodar:
$ git-sweep preview
Fetching from the remote
These branches have been merged into master:
branch1
branch2
branch3
branch4
branch5
To delete them, run again with `git-sweep cleanup`
De dentro do seu repositório (claro). Com esse comando ele apenas te deu a lista dos branches merged. Despois disso para limpar é só fazer um:
$ git-sweep cleanup
Fetching from the remote
These branches have been merged into master:
branch1
branch2
branch3
branch4
branch5
Delete these branches? (y/n) y
deleting branch1 (done)
deleting branch2 (done)
deleting branch3 (done)
deleting branch4 (done)
deleting branch5 (done)
All done!
Tell everyone to run `git fetch --prune` to sync with this remote.
(you don't have to, yours is synced)
Pronto, seu remote está limpinho. 😁
pip install git-sweep || easy_install git-sweep
Collecting git-sweep
Downloading https://files.pythonhosted.org/packages/68/71/a4b06ba2cd275a2cc1c1eef46ae655517c6b8b05326e8bf60b89e01f2a59/git-sweep-0.1.1.tar.gz
Collecting GitPython>=0.3.2RC1 (from git-sweep)
Downloading https://files.pythonhosted.org/packages/fe/e5/fafe827507644c32d6dc553a1c435cdf882e0c28918a5bab29f7fbebfb70/GitPython-2.1.11-py2.py3-none-any.whl (448kB)
100% |████████████████████████████████| 450kB 415kB/s
Collecting gitdb2>=2.0.0 (from GitPython>=0.3.2RC1->git-sweep)
Downloading https://files.pythonhosted.org/packages/da/30/a407568aa8d8f25db817cf50121a958722f3fc5f87e3a6fba1f40c0633e3/gitdb2-2.0.5-py2.py3-none-any.whl (62kB)
100% |████████████████████████████████| 71kB 698kB/s
Collecting smmap2>=2.0.0 (from gitdb2>=2.0.0->GitPython>=0.3.2RC1->git-sweep)
Downloading https://files.pythonhosted.org/packages/55/d2/866d45e3a121ee15a1dc013824d58072fd5c7799c9c34d01378eb262ca8f/smmap2-2.0.5-py2.py3-none-any.whl
Building wheels for collected packages: git-sweep
Running setup.py bdist_wheel for git-sweep ... done
Stored in directory: /home/phantom/.cache/pip/wheels/80/7c/88/bdaf52b019ca1d198dddfdb50872a5b6b2d63b86947d8e362d
Successfully built git-sweep
Installing collected packages: smmap2, gitdb2, GitPython, git-sweep
Successfully installed GitPython-2.1.11 git-sweep-0.1.1 gitdb2-2.0.5 smmap2-2.0.5
Instalou tudo certo, mas na hora de rodar o git-sweep preview ele buga.
git-sweep preview
git-sweep: command not found