Like most modern developer workflows, my workflow is based around Pull Requests. The ability to quickly create a feature branch to test something out is invaluable. But what happens to all of those local branches after the pull request has been merged and deleted on Github?

Typcially I forget about them until I need to run a git branch -l and have to dig through a hundred ancient branches names to find the one I need.

Thats where the power of git alias commands come in.

git forget command

As you can see, all of the branches I have locally are checked against the remote (in this case Github). If I have deleted them on the remote they are deleted locally. If I have local branches that I have not pushed to the remote, those will not be touched.

This command makes it super easy to keep your “git workspace” clean. Below is the alias you can add to your ~/.gitconfig file.

[alias]
   forget="! /usr/local/bin/git fetch -p && /usr/local/bin/git branch -vv | awk '/: gone]/{print $1}' | xargs /usr/local/bin/git branch -D"


blog comments powered by Disqus