A guest post from James Carr, a full stack engineer who has a hand in everything from devops to front end engineering. He is the co-founder and co-organizer of the Columbia, MO DevComo Group, and he works on Zapier.
I’ve been using Git and Github since at least 2008 for open source contributions, professional development, and to discover new libraries. Over the years, I’ve found that simple shortcuts can go a long way at improving productivity, and any time that is saved is time I can spend getting more awesome features finished and shipped. In this post, I’ll cover a few tools that can help enhance and improve your Github experience.
Back in 2010, an excellent piece was written on A successful Git branching model by Vincent Driessen on an effective branching strategy for teams working on many features and performing many releases. This lays down the concept of feature branches, current development branch (could potentially be shipped), and the pristine master branch that should always reflect a shippable product, no questions asked.
In more traditional Version Control Systems (VCS), branching can be both expensive and scary. In these setups, it is pretty common to fall into situations where feature X can’t be shipped because the code for feature Y is also in the repository and will break the site if it goes out (I’ve seen this many times unfortunately). With feature branches not only can you avoid this mess, you can also push those branches out so other team members can collaborate without fear, because they know that breaking code changes will not get pushed out until the feature is done.
On teams unfamiliar with the Git flow setup, I’ve found the git-flow add-on to be a great tool to kind of act as training wheels to get new people more acquainted with the process. Even more seasoned users can find the tool useful as a way to save a few keystrokes when creating and merging branches.
A final item to note is that most teams will use Github as a way to collaborate, in which case Github Flow might be better suited for your development cycle. Although team members may use Git Flow locally to create branches and work, merges take place on Github via pull-requests, so that the rest of the team can participate in quick code reviews and give feedback. This is an indispensable form of collaboration when you work on a distributed team where you can’t just show them your laptop and get feedback.
If you use Github Flow, two additional tools will help you do all of the steps involved without leaving the comfort of your command-line.
This add-on adds many handy utilities to Git that bundle up a lot of common operations into simple easy-to-use commands. You can find it on Github and install via Brew if you are on Mac OS X, otherwise you can follow the installation instructions on Github. Let’s look over some of the commands it provides that I’ve found to be the most useful.
One of my favorites is Git Squash. Sometimes you work on a branch and have tons of commits to push out. When doing a pull request on an upstream repo for a project you’re contributing to, the maintainer will likely find it pretty painful to have to dig through all of your changes across 300 commits (a lot can change between those commits too!).
git-squash command merges commits from a specified source branch into the current branch as a single commit and deletes the old branch. This also works really great if your team uses the Github Flow way of collaborating. At Zapier we typically use pull requests as a form of code review, and it is always beneficial for the team to be able to review all of the changes made in a single commit.
This is basically the same as using
git-rebase with the
-i option, although if you’ve used this before you’ve probably found yourself feeling a little bit like a ninja after finally getting it working right once you’ve done a thorough reading of the Git documentation. With
git-extras it is as easy as this:
$ git checkout -b new-feature
... add a few commits ..
$ git checkout develop
$ git squash new-feature "Cranked out new feature X!"
One of my very first searches when using Git was “how the heck do I undo the last commit?” when I made a bad mistake. Or even worse, “how do I undo the last three commits?” Although a quick Google will find you a few helpful Stackoverflow posts on how to do this,
git-undo provides a command that is easy to remember. Need to undo the last commit? Just type
git undo and it’s done! Or the last five commits? Easy:
git undo 5.
A common best practice most organizations adhere to is to not store sensitive information like database authentication details in their source repository. Of course it can be an easy mistake to accidentally do this and, realizing the mistake, delete it at a later date. But the file is still in your history and can still be accessed!
git-obliterate is handy in this situation, as it completely removes the offensive file from your entire history to act as if it was never added in the first place. For example, if you at one time added your AWS keys to your project because you didn’t know better, just run
git obliterate ec2.yaml and you’re good to go!
Hub is a command-line wrapper that makes it really easy to do things like fork repositories, view project issues and submit pull requests from the convenience of the command line. I’ve found Hub to be a huge boon to my productivity by reducing the time I spend navigating in my browser to do things on Github.
For example, say one of my teammates asks me to collaborate with them on a new project, say
django-knowledge. Knowing this is in our Github organization, I just run
git clone zapier/django-knowledge to clone the repo down. I can then run
git browse -- issues to view the issues for the project to pick up one of the feature requests to work on.
Forking and issuing a pull request is easy too! While in the repository, if you run
git fork it will fork the current repository to your personal account. You can now make any changes and commits you need to make (and even better, use
git-squash to roll those up into a single commit). Once you’re ready to push your feature out and issue a pull request, you can just run the following commands:
$ git push -u YOURUSERNAME feature
$ git pull-request "Here come my awesome features"
pull-request command will display the URL for the pull request you just issued against the upstream repository. You can even use the browse command to open the pull request up in a browser and start working with it.
That’s just the beginning… there are a lot of other useful features in Hub that combined with
git-extras can provide a complete solution to apply Github Flow quickly and easily to collaborate with your team.
Want To Learn More?
Hopefully, the tools mentioned here are enough to really enhance your team’s workflow and productivity on Github. In addition, here are a few more resources from Safari Books Online that are great to pursue if you’d like to learn more.
Safari Books Online has the content you need
|Version Control with Git, 2nd Edition takes you quickly from Git fundamentals to advanced techniques, and provides friendly yet rigorous advice for navigating the many functions of this open source version control system.|
|Developing a Backbone.js Edge contains an example application, called Hubbub, that illustrates the various features of the library (Hubbub repo on Github). Don’t worry, it’s not another Todo App–rather it’s a GitHub issue organizer. The application is more complex than most example applications and it uses a real API (Github’s). You’ll have a chance to build the application as you go through the book.|
|Git: Version Control for Everyone Beginner’s Guide is a step by step, practical guide, helping you learn the routine of version controlling all your content, every day.|
About the author
|James Carr is a full stack engineer who has a hand in everything from devops to frontend engineering. He is the co-founder and co-organizer of the Columbia, MO DevComo Group. Day and night he works on Zapier improving infrastructure automation and helping grow their ever growing list of API integrations. When not hacking on awesome technology he spends time with his wife, daughter and recently newborn son.|