Tagged: github

Adding pull requests to your .gitconfig using hub (and other useful aliases)

So a while back, I came across a post by thoughtbot describing how to streamline your git workflow with aliases, and I thought it was really useful. The problem is it didn’t quite fit how we work, because we use github flow¬†instead of¬†git-flow. Now, I’ve found it sort of annoying to have to open up github.com in a browser and actually click “Pull Request”, so I started looking for ways that this could be accomplished in the command line when I came across hub.

After one installs hub, a pull request can be initiated as easily as the following line:

hub pull-request "Added feature X"

There are several other useful things that can be done with hub, but those are beyond the scope of this blog post.

And on to the good stuff — here’s an excerpt from my ~/.gitconfig that makes some changes to the original one from the thoughtbot post above:

 c = commit -m
 a = add
 aa = !git add -u && git add . && git status
 cob = !sh -c 'git checkout -b $1 && git push -u origin $1' -
 done = !git push && hub pull-request

Note: if you’re wondering about the aliases that take arguments, read about those here

Now the process listed by thoughtbot would look like this:

1. Start a story with a new branch

git cob feature_x

2. Make changes and commit (and repeat)

vi file.rb
git aa
git c "Make changes"

3. Merge in your changes from your master branch (optional)*

git merge master

4. Finish the story and open a pull-request for approval

git done "Added feature X"

*Github will automatically merge in your master branch, so there’s really no need to do so manually before you create a pull-request unless you find that your team encounters merge conflicts often. If you do have a conflict, Github will let you know, and you can update your branch then.

And that’s it. Hope you enjoy!