If you haven’t heard of GitHub, there are tons of posts explaining the hows and whys of its awesomeness. This is not one of the posts. Instead, I want to quickly share some oft overlooked but tasty GitHub tidbits.
The GitHub Gem
$ gem install defunkt-github --source=http://gems.github.com/
Great. At this point, possibilities become reality. The gem has a few cool features, all of which are displayed via $ github -h, but the best feature by far is pull.
Here’s how it works: I have my fork of technoweenie’s exception_logger. I’ve cloned it and am sitting in the working directory. Suddenly I discover ryanb (of RailsCasts fame) has sent me a pull request. Open source’s finest moment.
So, I type $ github pull ryanb. A remote is added, a new branch is created, and Ryan’s changes are pulled into that branch. (It’s probably named ryanb/master.) I then review the changes and, if they rock, either rebase or merge them back into master. Like this:
$ git checkout master $ git merge ryanb/master $ git push
Already reviewed the changes on the web and know they’re legit? Just $ github pull --merge ryanb. This’ll grab the changes and merge them into master for you. Oh, right, you can also specify a branch. The assumption is master, but you know what they say about assumptions: you’re a jerk.
Thus: $ github pull—merge ryanb weird_branch
And just like that, GitHub pull requests are no longer a pain in the ass.
But really, this is just start. Please please please fork the gem and add awesome features. github clone, anyone?
Let’s say you want to peep some Rails changes. In classic vi style, j and k navigate between changes. c, t, and p lead you to the selected change’s commit, tree, or parent. h and l navigate between pages.
In fact, h and l will always go back and forward on any paginated page. We’ve written an evil twin which adds those hotkeys to any will_paginate call.
Also cool: s. If you’re logged in, hitting s will display and focus the search bar. I use this one the most.
Ranged Code Highlighting
Clicking on any line number then shift clicking a higher value line number selects a range. Super useful for code discussion. Discussion such as, “Dude, nonzero? is so awesome. Check it out!” (People definitely talk like that.)
Keep Your Dotfiles in Git
Okay, this isn’t strictly related to GitHub, but it’s good. You should be keeping your dotfiles in Git. Here are the steps to do so:
1. Create a ‘dotfiles’ directory.
2. Move your dotfiles to this new directory, sans leading dot. For example, to keep your ˜/.vimrc under version control, do this:
$ mv ˜/.vimrc ˜/Projects/dotfiles/vimrc. Rinse and repeat as necessary.
3. Add the following file to your dotfiles project, then run it: http://pastie.org/195036
4. Finally: $ git init && git add . Then: $ git commit -m ‘new dotfiles project’
You’re all set. Now your dotfiles that live in ˜ are symlinked to their counterparts in ˜/Projects/dotfiles. As a bonus, any time you git commit it will automatically git push. One of the entire points of keeping your files under version control is to back them up regularly.
I push to a private ‘dotfiles’ repo on GitHub. Others have created public repos. Your call.
For posterity’s sake, here’s my version controlled dotfiles:
bashrc gitconfig irbrc railsrc sake screenrc ssh vim vimrc
The best part?
The best part about GitHub, f’sure, is all the outrageously cool open source projects hosted on it. _why’s stuff, the jQuery plugins and mirrors, all the LISP projects, newer languages like Io, and of course the assorted GitHub-related projects.
Got something cool hosted there? Let us know.
Til next time, keep on hubbin’.
Update: GitHub Open Sores
I just created the GitHub account and did two things: created and pushed up some extractions from GitHub itself (like the jQuery hotkeys plugin) and also forked all the projects that are used on GitHub which we’re using on GitHub. Dude, meta. Anyway, have fun with that.