Git Cleanup
My normal development workflow:
- Create a new feature branch on my local machine for whatever project I am working on
- Build the feature (testing first!)
- Push the working feature to GitHub
- Create a pull request
- Pull request is reviewed/signed off
- Click the “Merge” button on GitHub and then “Delete branch”
- Checkout master on my local machine and pull the latest master from GitHub
- Repeat
I should probably remember to always delete the feature branch on my local machine after it’s merged on GitHub. I never manage this. Sometimes I don’t do this for a very long time and end up with 30+ branches. Then I don’t remember which ones are merged so I don’t know which ones I can delete. Things get messy. So I wrote a quick Git Alias to help me out. To create the alias run the following command from your terminal:
git config --global alias.cleanup '!git checkout master && git branch --merged | grep -v "*" | xargs -n 1 git branch -d'
This alias will automatically delete all branches which have already been merged with master. Just run it from the root of your Git project.
git cleanup
I hope this helps simplify your life as it did mine.
Need some extra development power?
I don't have a lot of time at the moment, but I'm always interested to hear about new projects. I'm particularly interested in EmberJS/Elixir projects and refactoring Rails monoliths. Drop me a line at hello [at] mattbeedle [dot] name or using my contact form http://www.mattbeedle.name/#page-contact.
Tweetcomments powered by Disqus